tf.newaxis 和 numpy newaxis

阅读更多
n [71]: a1 = tf.constant([2,2], name="a1")

In [72]: a1
Out[72]: 

# add a new dimension
In [73]: a1_new = a1[tf.newaxis, :]

In [74]: a1_new
Out[74]: 

# add one more dimension
In [75]: a1_new = a1[tf.newaxis, :, tf.newaxis]

In [76]: a1_new
Out[76]: 


>> x = np.arange(3)
>> x
array([0, 1, 2])
>> x.shape
(3,)

>> x[:, np.newaxis]
array([[0],
       [1],
       [2]])

>> x[:, None]
array([[0],
       [1],
       [2]])

>> x[:, np.newaxis].shape
 (3, 1)

 

你可能感兴趣的:(tf.newaxis 和 numpy newaxis)