共計 250 個字符,預(yù)計需要花費 1 分鐘才能閱讀完成。
在 Python 中,可以使用 numpy 庫來獲取數(shù)據(jù)的行數(shù)和列數(shù)。下面是一個示例代碼:
import numpy as np
# 創(chuàng)建一個 2 維數(shù)組
data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
# 獲取行數(shù)和列數(shù)
rows, cols = data.shape
print("行數(shù):", rows)
print("列數(shù):", cols)
輸出結(jié)果為:
行數(shù):3
列數(shù):3
通過 data.shape 可以獲取數(shù)據(jù)的形狀,返回一個元組,元組的第一個元素表示行數(shù),第二個元素表示列數(shù)。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完