简体   繁体   English

python3 numpy:数组的索引过多

[英]python3 numpy: too many indices for array

I have a value, just like: 我有一个价值,就像:

a = np.array({'a':1})

Then, I want to get the dict from a. 然后,我想从中获取命令。 But error happens when I use a[0]: 但是当我使用a [0]时发生错误:

IndexError: too many indices for array

I have a look at the shape of a: 我看一下形状:

>>> a.shape
()

So, how to get the value from a? 那么,如何从a获得价值?

您应该使用列表创建数组;

a = np.array([{'a':1}])

galmeriol is right. 加美洛尔是正确的。 Go for as he has suggested. 按照他的建议去。

>>> a.all()
{'a': 1}
>>>> a.all()['a']
1

You can access it like this, 您可以这样访问

import numpy

a = numpy.array({'a': 1, 'b': 2})
a.item()['a']
# 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM