Skip to content
Advertisement

How to access items from ndarray with dtype=object

How can I access data inside a numpy array with dtype=object?

JavaScript

The following raises an IndexError.

JavaScript
JavaScript

Advertisement

Answer

Since you passed in the dict to numpy.array() without putting it in a list, this is a zero-dimensional array. To index into a zero-dimensional array, you can use b.item() to access the element inside. For completeness, to access the data in the "a" key in your dictionary, you can use this.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement