Numpy array dimensions
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm currently trying to learn Numpy and Python. Given the following array: import numpy as N a = N.array([[1,2],[1,2]]) Is there a function that returns the dimensions of a (e.g.a is a 2 by 2 array)? size() returns 4 and that doesn't help very much. 回答1: It is .shape : ndarray. shape Tuple of array dimensions. Thus: >>> a.shape (2, 2) 回答2: import numpy as np >>> np.shape(a) (2,2) Also works if the input is not a numpy array but a list of lists >>> a = [[1,2],[1,2]] >>> np.shape(a) (2,2) 回答3: First: By convention, in Python world, the