1

It drives me crazy, but I can't figure it out I have a data matrix of (10000,4)

I need to select some rows where the elements of column 0

ind1=np.where( (data[:,0]>55) & (data[:,0]<65) )

I want to keep that data only so

keep_data=data[ind1,:]

But keep_data is now (1,10000,4)

Why is that?

P.S. What i do is th efollwing

keep_data=np.reshape(keep_data,(keep_data.shape[1],keep_data.shape[2]))
0

1 Answer 1

2

numpy.where returns a tuple.

Therefore, use ind1 = np.where((data[:,0]>55) & (data[:,0]<65))[0]

Notice the [0] indexing to select the only element of the tuple.

This is noted in the docs:

numpy.where(condition[, x, y])

Return elements, either from x or y, depending on condition.

If only condition is given, return the tuple condition.nonzero(), the indices where condition is True.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.