numpy的数组的大小 [英] size of NumPy array
本文介绍了numpy的数组的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一个相当于MATLAB
尺寸()
在numpy的命令?
在MATLAB,
>>>一个=零(2,5)
0 0 0 0 0
0 0 0 0 0
>>>尺寸(一)
2 5
在Python中,
>>>一个=零((2,5))
>>>
阵列([0,0,0,0,0],
[0,0,0,0,0。]])>>> ?????
解决方案
这就是所谓的numpy的形,并且可以通过 .shape
属性请求:
>>>一个=零((2,5))
>>>一个形状
(2,5)
如果您preFER功能,您还可以使用 numpy.shape(一)
。
Is there an equivalent to the MATLAB
size()
command in Numpy?
In MATLAB,
>>> a = zeros(2,5)
0 0 0 0 0
0 0 0 0 0
>>> size(a)
2 5
In Python,
>>> a = zeros((2,5))
>>>
array([[ 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0.]])
>>> ?????
解决方案
This is called the "shape" in NumPy, and can be requested via the .shape
attribute:
>>> a = zeros((2, 5))
>>> a.shape
(2, 5)
If you prefer a function, you could also use numpy.shape(a)
.
这篇关于numpy的数组的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文