Numpy中的newaxis屬性:np.newaxis

意思就是字面意思,建立新維度
具體來看例子

>>>import numpy as np
>>>np.newaxis:插入新維度
>>>a=np.array([1,2,3,4,5])
>>>aa=a[np.newaxis,:]
>>>aa.shape
(1, 5)
>>>aa
[[1 2 3 4 5]]
                
>>>a=np.array([1,2,3,4,5])
>>>aa=a[:,np.newaxis]
>>>aa.shape
(5, 1)
>>>aa
[[1]
[2]
[3]
[4]
[5]]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章