Skip to content

BUG: np.where converts floats to int #15148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pensono opened this issue Dec 22, 2019 · 4 comments
Closed

BUG: np.where converts floats to int #15148

pensono opened this issue Dec 22, 2019 · 4 comments

Comments

@pensono
Copy link

pensono commented Dec 22, 2019

Reproducing code example:

import numpy as np

data = np.arange(0, 1, .1)
print(data)
test = np.where(data < .5)
print(test)

Error message:

Expected to print:

[0.  0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
[0., .1, .2, .3, .4]

Actually prints:

[0.  0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
(array([0, 1, 2, 3, 4], dtype=int64),)

It seems that np.where is also returning a single element tuple.

Numpy/Python version information:

1.17.4 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]

@mattip
Copy link
Member

mattip commented Dec 22, 2019

xref gh-12470, this change seems wrong.

@mattip mattip changed the title np.where converts floats to int BUG: np.where converts floats to int Dec 22, 2019
@mattip
Copy link
Member

mattip commented Dec 22, 2019

it seems the change is right but there is some other problem

@mattip
Copy link
Member

mattip commented Dec 22, 2019

This is documented, and is functioning according to the note at the top of the documentation.

When only condition is provided, this function is a shorthand for np.asarray(condition).nonzero(). Using nonzero directly should be preferred, as it behaves correctly for subclasses. The rest of this documentation covers only the case where all three arguments are provided.

Closing. Please reopen if something still is not clear.

@mattip mattip closed this as completed Dec 22, 2019
@eric-wieser
Copy link
Member

You're looking for data[data < .5]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants