>>> b=np.expand_dims(a,-1); a.shape;a;b.shape;b
(2, 3)
array([[1, 2, 3],
[4, 5, 6]])
(2, 3, 1)
array([ [ [1],
[2],
[3]],
[ [4],
[5],
[6] ] ])
|
>>> b=np.expand_dims(a,0); a.shape;a;b.shape;b
(2, 3)
array([[1, 2, 3],
[4, 5, 6]])
(1, 2, 3)
array([ [ [1, 2, 3],
[4, 5, 6] ] ])
|
>>> b=np.expand_dims(a,1); a.shape;a;b.shape;b
(2, 3)
array([[1, 2, 3],
[4, 5, 6]])
(2, 1, 3)
array([ [ [1, 2, 3] ],
[ [4, 5, 6] ] ])
|
>>> b=np.expand_dims(a,2); a.shape;a;b.shape;b
(2, 3)
array([[1, 2, 3],
[4, 5, 6]])
(2, 3, 1)
array([ [ [1],
[2],
[3] ],
[ [4],
[5],
[6] ] ])
|
|
>>> sum=tf.reduce_sum(al2,1); sum; print(sum.eval())
<tf.Tensor 'Sum_2:0' shape=(2, 4) =(B,D)dtype=int32>
[[ 36 72 108 144]
[ 66 132 198 264]] |
sum=tf.reduce_sum(al1,2); sum; print(sum.eval())
<tf.Tensor 'Sum_4:0' shape=(2, 3) =(B,T) dtype=int32>
[[110 120 130]
[210 220 230]] |
>>> al1=tf.expand_dims(al,1); al1; print(al1.eval())
<tf.Tensor 'ExpandDims_28:0' shape=(2, 1, 3) dtype=int32>
[[[11 12 13]]
[[21 22 23]]]
|
|
|