8000 Inconsistent behaviour in array multiplication using *= · Issue #6379 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Inconsistent behaviour in array multiplication using *= #6379

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
0mar opened this issue Sep 28, 2015 · 1 comment
Closed

Inconsistent behaviour in array multiplication using *= #6379

0mar opened this issue Sep 28, 2015 · 1 comment

Comments

@0mar
Copy link
0mar commented Sep 28, 2015

I saw similar reports in #6074 and #4707, but I didn't find any report matching this issue exacly.
When multiplying arrays a and b, a*=b and a=a*b are not equivalent if their types are different.

The same happens with addition.

In Numpy 1.8.2, on python 3.4, different behaviour is observed in the following two cases:

import numpy as np

#1

a1 = np.array([1,2])
c = np.array([0.7,0.7])
a1*= c
print(a1,a1.dtype)

Output:
[0 1] int64
#2

a1 = np.array([1,2])
c = np.array([0.7,0.7])
a1= a1*c
print(a1,a1.dtype)

Output
[ 0.7 1.4] float64

However, I'm not sure whether this is a bug, or just a matter of semantics.

@seberg
Copy link
Member
seberg commented Sep 28, 2015

There is no inconsistency here, because the first example corresponds to:

a1[...] = a1 * c

since it is in-place the data type cannot change, so that there is an (unsafe) cast involved. Note that there is a deprecation warning about this, and it may be turned into an error in the future (or maybe it was already in 1.10). Which will force the user to make the cast manually.

If you have any further questions, feel free to ask.

@seberg seberg closed this as completed Sep 28, 2015
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