Numpy 的 shape
屬性以 tuple
形式返回沿數組每個軸的元素數量。
例子
一維數組
x = np.array([1,2,3])
print(x.shape)
(3,)
,
後麵什麽都沒有,僅表示該數組是一個包含 3 個元素的向量。
二維數組
x = np.array([[1,2,3],[4,5,6]])
print(x.shape)
(2, 3)
這告訴我們x
有 2 行和 3 列。
訪問元組內的值
請注意,由於返回類型隻是一個元組,因此您可以使用 []
語法訪問實際數字,如下所示:
x = np.array([1,2,3])
print(x.shape[0])
3
相關用法
- Python NumPy shares_memory方法用法及代碼示例
- Python Wand sharpen()用法及代碼示例
- Python Wand shade()用法及代碼示例
- Python shutil.copyfile()用法及代碼示例
- Python shutil.unregister_unpack_format()用法及代碼示例
- Python shutil.get_terminal_size()用法及代碼示例
- Python shutil.get_archive_formats()用法及代碼示例
- Python shutil.which()用法及代碼示例
- Python shutil.copytree()用法及代碼示例
- Python shutil.copymode()用法及代碼示例
- Python shutil.unpack_archive()用法及代碼示例
- Python shutil.move()用法及代碼示例
- Python shutil.copy2()用法及代碼示例
- Python shutil.unregister_archive_format()用法及代碼示例
- Python shutil.chown()用法及代碼示例
- Python shutil.copyfileobj()用法及代碼示例
- Python shlex.join用法及代碼示例
- Python shutil.copystat()用法及代碼示例
- Python shlex.quote用法及代碼示例
- Python shutil.copy()用法及代碼示例
- Python shutil.get_unpack_formats()用法及代碼示例
- Python shutil.disk_usage()用法及代碼示例
- Python sklearn.cluster.MiniBatchKMeans用法及代碼示例
- Python NumPy squeeze方法用法及代碼示例
- Python scipy.ndimage.binary_opening用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | shape property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。