numpy.newaxis从字面上来理解就是用来创建新轴的,或者说是用来对array进行维度扩展的。
>>> import numpy as np>>> x = np.array([1, 2, 3, 4])>>> print x.shape
>>> x1 = x[np.newaxis, :]>>> print x1.shape>>> print x1
>>> x2 = x[:, np.newaxis]>>> print x2.shape>>> print x2
>>> y = x[None, :]>>> print y.shape>>> print y
>>> print np.axis
联系客服