-
-
Notifications
You must be signed in to change notification settings - Fork 132
Usage: confused by np.where
behaviour and fill_value
#871
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
Comments
OK I understand what's happening now. It would be good to call this behaviour out in the docstring |
In general, (a.fill_value == 1) = False = (array == 1).fill_value
np.where(False, np.nan, a.fill_value) = np.nan = np.where((array == 1), np.nan, a).fill_value
(a.fill_value < 1) = True = (array < 1).fill_value
np.where(True np.nan, a.fill_value) = 0 = np.where((array < 1), np.nan, a).fill_value The reasoning is the following: fill_values propagate through elemwise because we expect elemwise fns to produce mostly fill_values. If it was otherwise, we'd need to densify. |
Got it. thanks! Feel free to close if you don't think the docstring needs to be updated. |
If we still want to add this in the docstring, we can do so somewhere around here. We can also take a much simpler example to explain how a = COO.from_numpy(np.eye(3), fill_value=1)
b = COO.from_numpy(np.eye(3), fill_value=2)
c = a + b
print(c.fill_value) # 1.0 + 2.0 = 3.0 Mentioning "Since |
Uh oh!
There was an error while loading. Please reload this page.
Please provide a description of what you'd like to do.
More dependable fill_value preservation in
where
Example Code
For
mask=array==1
,mask.fill_value=False
and thearray
's fill_value is preserved in the np.where call.For
mask=array<1
,mask.fill_value=True
and thearray
's fill_value is NOT preserved in the np.where call.This kind of behaviour is hard to rely on in a library. Is it a bug?
The text was updated successfully, but these errors were encountered: