8000 Numpy silently assigns zeroes · Issue #12449 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Numpy silently assigns zeroes #12449

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
hhristov94 opened this issue Nov 25, 2018 · 3 comments
Closed

Numpy silently assigns zeroes #12449

hhristov94 opened this issue Nov 25, 2018 · 3 comments

Comments

@hhristov94
Copy link
hhristov94 commented Nov 25, 2018

Numpy silently assigns zeroes instead of the correct array if the array has a negative fraction.

Reproducing code example:

A = np.array([[3,2,4],
              [2,1,3],
              [1,2,4]])
b = A[1,0:3] - 0.66*A[0,0:3]
A[1,1:3] = b[1:3]

A

Output:

array([[3, 2, 4],
       [2, 0, 0],
       [1, 2, 4]])

Numpy/Python version information:

OS: Windows 10
Numpy version : 1.14.5
Python version : 3.6.6
1.14.5 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)]

@hhristov94
Copy link
Author

Updated to Numpy version 1.15.4 . The issue still persists.

@eric-wieser
Copy link
Member
eric-wieser commented Nov 25, 2018

This fails for the same reason as:

>>> arr = np.array([1, 2, 3])
>>> arr.dtype
int  # or something
>>> arr[0] = 1.5
>>> arr.dtype
int  # unchanged
>>> arr[0]
1  # 1.5 is not an int, so we had to round

Assigning to an array never changes its type.

You could argue we should emit a warning or error here, rather than rounding. I think there are multiple issues open about that.

@eric-wieser
Copy link
Member

Duplicate of #8733

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

No branches or pull requests

2 participants
0