Numpy 的幾種屬性
- ndim:維度
- shape:行數和列數
- size:元素個數
使用numpy首先要導入模塊
import numpy as np #為了方便使用numpy 採用np簡寫
列表轉化為矩陣:
array = np.array([[1,2,3],[2,3,4]]) #列表轉化為矩陣
print(array)
"""
array([[1, 2, 3],
[2, 3, 4]])
"""
numpy 的幾種屬性
接著我們看看這幾種屬性的結果:
print('number of dim:',array.ndim) # 維度
# number of dim: 2
print('shape :',array.shape) # 行數和列數
# shape : (2, 3)
print('size:',array.size) # 元素個數
# size: 6
最後
如果你覺得本文對你有幫助,希望可以關注並轉發,這樣我會更有動力更新的。
閱讀更多 僱個城管打天下y 的文章