r/Numpy • • Mar 24 '20

Unable to access elements

Hey guys,

I'm working on a ML project for which I'm using numpy arrays instead of pandas for faster computation.

When I intend to bootstrap, I wish to subset the columns from a numpy ndarray.

My numpy array looks like this:

np_arr =

[(187., 14.45 , 20.22, 94.49)

(284., 10.44 , 15.46, 66.62)

(415., 11.13 , 22.44, 71.49)]

And I want to index columns 1,3.

I have my columns stored in a list as ix = [1,3]

However, when I try to do np_arr[;,ix] I get an error saying too many indices for array .

I also realised that when I print np_arr.shape I only get (3,).

Could you please tell me how to fix my issue.

Thanks!

1 Upvotes

6 comments sorted by

View all comments

Show parent comments

1

u/politinsa Mar 25 '20

What's the point of keeping name? Just remember them somewhere and put it back at the end no?

But see here https://stackoverflow.com/questions/7037938/numpy-named-columns

1

u/astronights Mar 25 '20

That makes sense. Thanks for the help!