Reputation: 139
I am trying to do multiple indices. However, it is showing the error of too many indices. Please help me and if you have some doubts or confusion in it then please leave comments in the comment box.
My result has (6561114,) shape and I want to indices the whole first row for instance ([array([-1., 1., 0., 0., 1.]), array([[43., 0., 43., 1., 2.]]), array([-43., 43., 0., 2., 3.]) and then from 3 columns I want to extract each value of array-like [-1,43,-43],[1,0,43], and so on.
This is Output:-
array([array([-1., 1., 0., 0., 1.]),
array([[43., 0., 43., 1., 2.]]),
array([-43., 43., 0., 2., 3.]), ...,
array([-1.406830e+01, 3.552240e+01, 2.145410e+01,
9.492236e+06,
9.492237e+06]),
array([[1.421949e+02, 2.145410e+01, 1.636490e+02, 9.492237e+06,
9.492238e+06],
[3.387300e+01, 1.636490e+02, 1.975220e+02, 9.492238e+06,
9.492239e+06]]),
array([-1.9052487e+02, 1.9752200e+02, 6.9971300e+00,
9.4922390e+06,
9.4922400e+06])], dtype=object)
This is what error looks like:-
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-29-537ba6ddfd42> in <module>
----> 1 result1[0,:]
IndexError: too many indices for array
Upvotes: 0
Views: 221
Reputation: 87
Check in second array you are using 2 [] braces.
Here array([[43., 0., 43., 1., 2.]])
you are using 2 [] braces, remove [] braces, and use it
I am using this code, and its working fine
Check using print(a[0]) and post your output.
import numpy as np
a=np.array([np.array([-1., 1., 0., 0., 1.]),np.array([43., 0., 43., 1., 2.]),np.array([-43., 43., 0.2., 3.])],dtype=object)
print(a[:,0])
Upvotes: 1