共計 267 個字符,預計需要花費 1 分鐘才能閱讀完成。
要讀取矩陣的行數和列數,可以使用 numpy 庫中的 shape 屬性。下面是一個示例代碼:
import numpy as np
# 創建一個 3x4 的矩陣
matrix = np.array([[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]])
# 獲取矩陣的行數和列數
num_rows, num_cols = matrix.shape
# 打印行數和列數
print(" 矩陣的行數為:", num_rows)
print(" 矩陣的列數為:", num_cols)
運行上面的代碼,將輸出以下結果:
矩陣的行數為:3
矩陣的列數為:4
丸趣 TV 網 – 提供最優質的資源集合!
正文完