2

numpy.where is converting float array to int.

Using jupyter notebook

x = np.array([1.0, 2.3, 1.3, 2.9])
print(x)
print(np.where(x>.1))

I was expecting a result like this: [1.0, 2.3, 1.3, 2.9]. I am sure I am missing something.

1 Answer 1

3

numpy.where gives you a list of indexes where the condition holds true. You would want to use those indexes in the actual array to get your elements

In [44]: import numpy as np                                                                                                                                                                             

In [45]: x = np.array([1.0, 2.3, 1.3, 2.9])                                                                                                                                                             

In [47]: np.where(x>.1)                                                                                                                                                                                 
Out[47]: (array([0, 1, 2, 3]),)

In [48]: x[np.where(x>.1)]                                                                                                                                                                              
Out[48]: array([1. , 2.3, 1.3, 2.9])
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.