Numpy 数组维度 [英] Numpy array dimensions
本文介绍了Numpy 数组维度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在尝试学习 Numpy 和 Python.给定以下数组:
将 numpy 导入为 npa = np.array([[1,2],[1,2]])
是否有返回 a
维度的函数(例如,a 是一个 2 x 2 的数组)?
size()
返回 4 而这并没有多大帮助.
解决方案
<块引用>ndarray.形状
数组维度的元组.
因此:
<预><代码>>>>一个形状(2, 2)I'm currently trying to learn Numpy and Python. Given the following array:
import numpy as np
a = np.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.
解决方案
It is .shape
:
ndarray.shape
Tuple of array dimensions.
Thus:
>>> a.shape
(2, 2)
这篇关于Numpy 数组维度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文