1. 程式人生 > >Python-numpy庫學習系列——newaxis

Python-numpy庫學習系列——newaxis

今天看原始碼,發現了newaxis庫的屬性,貌似很有用的樣子,就自己試驗了下

import numpy as np
x=np.array([1,2,3]) #建立矩陣

y=np.array([1,2,3])[:,np.newaxis]#增加維度,

x.shape
Out[11]: (3,)

y.shape
Out[12]: (3, 1)

z=y[np.newaxis]

z.shape
Out[14]: (1, 3, 1)

z1 = y[None]

z1.shape
Out[16]: (1, 3, 1)

np.transpose(z1).shape
Out[17]: (1, 3
, 1) np.transpose(y).shape Out[18]: (1, 3)

在一維的情況下,正好就意味著矩陣轉置~
多維的情況下,就可能是他真正的作用了,增加維度,規範化計算

持續更新中…