numpy.newaxis
The newaxis object can be used in all slicing operations to create an axis of length one. newaxis is an alias for ‘None’, and‘None’can be used in place of this with the same result.
newaxis是None的一个别名。
实例
import numpy as np
x = np.array([[1,2,3],[4,5,6],[7,8,9]])
a = x[:,np.newaxis,:]
b = x[:,:,np.newaxis]
print a
print b
输出
注意:np.newaxis的位置对数组的改变,常用于从数据中取列的操作中