本文實例講述了Python簡單獲取二維數組行列數的方法。分享給大家供大家參考,具體如下:
import numpy as npx = np.array([[1,2,5],[2,3,5],[3,4,5],[2,3,6]])# 輸出數組的行和列數print x.shape # (4, 3)# 只輸出行數print x.shape[0] # 4# 只輸出列數print x.shape[1] # 3
本機測試運行結果如下圖所示:
或者:
>>> arr = [[1,4,7,10,15], [2,5,8,12,19], [3,6,9,16,22], [10,13,14,17,24]]>>> len(arr) #行數4>>> len(arr[0]) #列數5
希望本文所述對大家Python程序設計有所幫助。
|
新聞熱點
疑難解答