np.newaxis用法详解


np.newaxis,增加维度

In [1]: np.linspace(1, 10, 10)
Out[1]: array([  1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,  10.])

In [2]: np.linspace(1, 10, 10)[np.newaxis,:]
Out[2]: array([[  1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,  10.]])

In [3]: np.linspace(1, 10, 10)[:,np.newaxis]
Out[3]:
array([[  1.],
       [  2.],
       [  3.],
       [  4.],
       [  5.],
       [  6.],
       [  7.],
       [  8.],
       [  9.],
       [ 10.]])

In [4]: np.linspace(1, 10, 10).shape
Out[4]: (10,)

In [5]: np.linspace(1, 10, 10)[np.newaxis,:].shape
Out[5]: (1, 10)

In [6]: np.linspace(1, 10, 10)[:,np.newaxis].shape
Out[6]: (10, 1)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM