height, width = a.shape
Run Code Online (Sandbox Code Playgroud)
但是请注意,ndarray矩阵坐标(i,j)与图像坐标(x,y)相反.那是:
i, j = y, x # and not x, y
Run Code Online (Sandbox Code Playgroud)
此外,Python元组支持索引,因此您可以访问单独的维度,如下所示:
dims = a.shape
height = dims[0]
width = dims[1]
Run Code Online (Sandbox Code Playgroud)