共計 312 個字符,預(yù)計需要花費 1 分鐘才能閱讀完成。
在 Python 中,可以使用 numpy 庫來讀取矩陣的行和列數(shù)。下面是一個示例:
import numpy as np
# 創(chuàng)建一個 3x4 的矩陣
matrix = np.array([[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]])
# 讀取矩陣的行數(shù)和列數(shù)
num_rows = matrix.shape[0] # 行數(shù)
num_cols = matrix.shape[1] # 列數(shù)
print(" 行數(shù):", num_rows)
print(" 列數(shù):", num_cols)
輸出結(jié)果為:
行數(shù): 3
列數(shù): 4
在上述示例中,使用 numpy
庫中的 array
函數(shù)創(chuàng)建了一個 3 ×4 的矩陣。然后,通過 shape
屬性獲取矩陣的行數(shù)和列數(shù)。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完