NumPy 数组维度大小获取:使用 np.shape 函数
可以使用 np.shape 函数来获取 np.array 的每一维的大小。
示例代码如下:
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
shape = np.shape(arr)
print(shape)
输出结果为:
(2, 3)
其中,(2, 3) 表示 np.array arr 的第一维大小为 2,第二维大小为 3。
原文地址: https://www.cveoy.top/t/topic/qocl 著作权归作者所有。请勿转载和采集!