How do I access the dictionary inside the array?
import numpy as np
x = np.array({'x': 2, 'y': 5})
My initial thought:
x['y']
Index Error: not a valid index
x[0]
Index Error: too many indices for array
How do I access the dictionary inside the array?
import numpy as np
x = np.array({'x': 2, 'y': 5})
My initial thought:
x['y']
Index Error: not a valid index
x[0]
Index Error: too many indices for array
If you add square brackets to the array assignment you will have a 1-dimensional array:
then you could use:
I believe it would make more sense.
You have a 0-dimensional array of object dtype. Making this array at all is probably a mistake, but if you want to use it anyway, you can extract the dictionary by indexing the array with a tuple of no indices:
or by calling the array's
item
method: