Hello,
when I try in my script to divide a masked array by a scalar I get an error. The instruction is:
sppa = sp / 100.
sp is a masked array with ndim = 3.
error is: Traceback (most recent call last): File "/media/nethome/Work/workspace/interimEnso/src/mlBudget.py", line 95, in <module> sppa = sp / 100. File "/usr/lib/pymodules/python2.7/numpy/ma/core.py", line 3673, in __div__ return divide(self, other) File "/usr/lib/pymodules/python2.7/numpy/ma/core.py", line 1072, in __call__ m |= ma ValueError: invalid return array shape
The interesting thing is that this error only occurs after a tiling instruction:
sp4d = N.tile(sp, (ninterf, 1, 1, 1))
If I do the division before the tiling I don't get an error. There's also no error if I do the division with N.divide(sp, 100.).
Also printing the array sp after tiling doesn't work, while it works before. If I debug the script with eclipse/PyDev, in the variables window I get the message "Unable to get repr for <class 'numpy.ma.core.MaskedArray'>" for the sp array after tiling.
The tiling operation shouldn't change the array, should it? Is this a bug, or is it expected behaviour?
Regards, Martin Groszhauser
If I try to print the
2012/2/1 martin großhauser mgroszhauser@gmail.com:
Hello,
when I try in my script to divide a masked array by a scalar I get an error. The instruction is:
sppa = sp / 100.
sp is a masked array with ndim = 3.
error is: Traceback (most recent call last): File "/media/nethome/Work/workspace/interimEnso/src/mlBudget.py", line 95, in <module> sppa = sp / 100. File "/usr/lib/pymodules/python2.7/numpy/ma/core.py", line 3673, in __div__ return divide(self, other) File "/usr/lib/pymodules/python2.7/numpy/ma/core.py", line 1072, in __call__ m |= ma ValueError: invalid return array shape
The interesting thing is that this error only occurs after a tiling instruction:
sp4d = N.tile(sp, (ninterf, 1, 1, 1))
If I do the division before the tiling I don't get an error. There's also no error if I do the division with N.divide(sp, 100.).
Also printing the array sp after tiling doesn't work, while it works before. If I debug the script with eclipse/PyDev, in the variables window I get the message "Unable to get repr for <class 'numpy.ma.core.MaskedArray'>" for the sp array after tiling.
The tiling operation shouldn't change the array, should it? Is this a bug, or is it expected behaviour?
Regards, Martin Groszhauser
I forgot to mention that I'm using Numpy 1.5.1 from Ubuntu 11.04 (1.5.1-1ubuntu2).
2012/2/1 martin großhauser mgroszhauser@gmail.com
2012/2/1 martin großhauser mgroszhauser@gmail.com:
Hello,
when I try in my script to divide a masked array by a scalar I get an error. The instruction is:
sppa = sp / 100.
sp is a masked array with ndim = 3.
error is: Traceback (most recent call last): File "/media/nethome/Work/workspace/interimEnso/src/mlBudget.py", line 95, in <module> sppa = sp / 100. File "/usr/lib/pymodules/python2.7/numpy/ma/core.py", line 3673, in
__div__
return divide(self, other) File "/usr/lib/pymodules/python2.7/numpy/ma/core.py", line 1072, in
__call__
m |= ma ValueError: invalid return array shape
The interesting thing is that this error only occurs after a tiling
instruction:
sp4d = N.tile(sp, (ninterf, 1, 1, 1))
If I do the division before the tiling I don't get an error. There's also no error if I do the division with N.divide(sp, 100.).
Also printing the array sp after tiling doesn't work, while it works before. If I debug the script with eclipse/PyDev, in the variables window I get the message "Unable to get repr for <class 'numpy.ma.core.MaskedArray'>" for the sp array after tiling.
The tiling operation shouldn't change the array, should it? Is this a bug, or is it expected behaviour?
Regards, Martin Groszhauser
I forgot to mention that I'm using Numpy 1.5.1 from Ubuntu 11.04 (1.5.1-1ubuntu2).
I can't reproduce this bug with the latest numpy from github master. Perhaps it has been fixed by now?
Ben Root
Le 01/02/2012 21:09, Benjamin Root a écrit :
I can't reproduce this bug with the latest numpy from github master. Perhaps it has been fixed by now?
Hi,
I've no idea what's going on, but here is my $0.02 contribution. I reproduced the bug (numpy 1.5.1) with a rather minimal script. See attached.
Best, Pierre
On Wed, Feb 1, 2012 at 10:57 PM, Pierre Haessig pierre.haessig@crans.org wrote:
I've no idea what's going on, but here is my $0.02 contribution. I reproduced the bug (numpy 1.5.1) with a rather minimal script. See attached.
I reproduced the issue with Pierre's script also in numpy 1.6.1 and latest github (2.0.0.dev-b8bfcd0). In newer versions the error message is:
Traceback (most recent call last): File "ma_tiling_issue.py", line 18, in <module> a/100. #raises ValueError: invalid return array shape File "/usr/local/lib/python2.7/dist-packages/numpy/ma/core.py", line 3654, in __div__ return divide(self, other) File "/usr/local/lib/python2.7/dist-packages/numpy/ma/core.py", line 1078, in __call__ m |= ma ValueError: non-broadcastable output operand with shape (3,3,3) doesn't match the broadcast shape (1,3,3,3)
I still don't know what's going on. Is the internal representation (shape) of the array changed by the tile instruction?
I created a ticket: http://projects.scipy.org/numpy/ticket/2035
On 02/02/2012 02:52 AM, martin großhauser wrote:
On Wed, Feb 1, 2012 at 10:57 PM, Pierre Haessig pierre.haessig@crans.org wrote:
I've no idea what's going on, but here is my $0.02 contribution. I reproduced the bug (numpy 1.5.1) with a rather minimal script. See attached.
I reproduced the issue with Pierre's script also in numpy 1.6.1 and latest github (2.0.0.dev-b8bfcd0). In newer versions the error message is:
Traceback (most recent call last): File "ma_tiling_issue.py", line 18, in<module> a/100. #raises ValueError: invalid return array shape File "/usr/local/lib/python2.7/dist-packages/numpy/ma/core.py", line 3654, in __div__ return divide(self, other) File "/usr/local/lib/python2.7/dist-packages/numpy/ma/core.py", line 1078, in __call__ m |= ma ValueError: non-broadcastable output operand with shape (3,3,3) doesn't match the broadcast shape (1,3,3,3)
I still don't know what's going on. Is the internal representation (shape) of the array changed by the tile instruction?
I created a ticket: http://projects.scipy.org/numpy/ticket/2035 _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
This is triggered when the array's mask is not 'False' and appears to be due to the call on line 827 of numpy/lib/shape_base.py: c = _nx.array(A,copy=False,subok=True,ndmin=d)
where _nx is 'import numpy.core.numeric as _nx'. Also, setting 'copy=True' in the call does not change anything.
You probably can get around it by passing a copy to np.tile(): sp4d = np.tile(a.copy(), (4, 1, 1, 1))
Bruce