numpy中newaxis的用法

版权声明:本文为fourierr原创文章,未经博主fourier允许不得转载。 https://blog.csdn.net/qq_34562093/article/details/80611183

newaxis顾名思义就是插入新维度的意思,比如原来是一维数剧变成二维数剧,原来是二维变成三维,

python将二维数组变为三维数组的举例如下:

x_data = np.linspace(-1,1,6)
a=x_data.reshape((2,3))
c = a[:,np.newaxis,:]
b = a[np.newaxis,:,:]
d = a[:,:,np.newaxis]

print(a.shape)
print(b.shape)
print(c.shape)
print(d.shape)
print('________________')

输出结果:

D:\python\python.exe D:/pycharm/workspace/work_3.6.1/test01.py
(2, 3)
(1, 2, 3)
(2, 1, 3)
(2, 3, 1)
________________


Process finished with exit code 0

猜你喜欢

转载自blog.csdn.net/qq_34562093/article/details/80611183
今日推荐