Thanks to visit codestin.com
Credit goes to github.com

Skip to content

append bug : masked array #478

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
bblay opened this issue Oct 2, 2012 · 4 comments
Closed

append bug : masked array #478

bblay opened this issue Oct 2, 2012 · 4 comments

Comments

@bblay
Copy link

bblay commented Oct 2, 2012

The source data should not be modified by numpy.append:

import numpy, numpy.ma

data = numpy.arange(20).reshape(4,5)
data[:2, :2] = -1
data = numpy.ma.masked_less(data, 0)

print "Before", data.shape, data.mask.shape 
new_array = numpy.append(data, data[:, :1], axis=1)
print "After", data.shape, data.mask.shape 

Output:

Before (4, 5) (4, 5)
After (4, 5) (5, 4)

(using v1.6.1)

@pelson
Copy link
Contributor

pelson commented Oct 2, 2012

Looks like this is fixed on master.

On 1.6.1:

In [1]: import numpy

In [2]: data = numpy.arange(6).reshape(3, 2)

In [3]: data = numpy.ma.masked_greater(data, 0)

In [4]: new_arr = numpy.append(data, data[:, -1:], axis=1)

In [5]: print data.shape
(3, 2)

In [6]: print data.mask
[[False  True  True]
 [ True  True  True]]

In [7]: print data.mask.shape
(2, 3)

In [8]: print new_arr.mask
False

In [9]: print new_arr.shape
(3, 3)

(note that the original data's mask shape has been changed)

In numpy '1.8.0.dev-e18e744':

In [3]: import numpy

In [4]: data = numpy.arange(6).reshape(3, 2)

In [5]: data = numpy.ma.masked_greater(data, 0)

In [6]: new_arr = numpy.append(data, data[:, -1:], axis=1)

In [7]: print data.shape
(3, 2)

In [8]: print data.mask
[[False  True]
 [ True  True]
 [ True  True]]

In [9]: print data.mask.shape
(3, 2)

In [10]: print new_arr.mask
False

In [11]: print new_arr.shape
(3, 3)

It would be nice if new_arr had the appropriate mask, I found a relevant request here: http://projects.scipy.org/numpy/ticket/1623

@jjhelmus
Copy link
Contributor

The original issue from @bblay has been fixed for quite some time as indicated by @pelson and is still fixed in the current master. The inappropriate mask issue was dicussed on the numpy mailing list in September 2010. Trac ticket (1623) became GH #2219 and was closed with the addition of ma.append in #4339. I believe with this change this issue can be closed.

@jjhelmus
Copy link
Contributor

As an example of the new behavior

import numpy as np

print np.version.version

data = np.arange(6).reshape(3,2)
data = np.ma.masked_greater(data, 0)
new_arr = np.ma.append(data, data[:, -1:], axis=1)

print "data.shape", data.shape
print "data.mask", data.mask
print "data.mask.shape", data.mask.shape
print "new_arr.mash", new_arr.mask
print "new_arr.mask.shape", new_arr.mask.shape
1.11.0.dev0+941a4e0
data.shape (3, 2)
data.mask [[False  True]
 [ True  True]
 [ True  True]]
data.mask.shape (3, 2)
new_arr.mash [[False  True  True]
 [ True  True  True]
 [ True  True  True]]
new_arr.mask.shape (3, 3)

@charris
Copy link
Member

charris commented Sep 28, 2015

OK, thanks for the heads up. Closing.

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

4 participants