la, 2008-05-31 kello 17:56 -0400, Tony Yu kirjoitti: [clip] > I've been playing around with some software using numpy 1.0.4 and took > a crack at upgrading it to numpy 1.1.0, but I ran into some strange > behavior when assigning to slices of a masked array. [clip] > In [1]: import numpy > > In [2]: masked = numpy.ma.masked_array([[1, 2, 3, 4, 5]], mask=False) > > In [3]: masked[:] = numpy.fliplr(masked.copy()) > > In [4]: print masked > [[5 4 3 2 1]] > > In [5]: masked[:] = numpy.fliplr(masked) > > In [6]: print masked > [[1 2 3 2 1]]
Note that >>> numpy.fliplr(masked).base.base.base.base is masked.base True The reason for the strange behavior of slice assignment is that when the left and right sides in a slice assignment are overlapping views of the same array, the result is currently effectively undefined. Same is true for ndarrays: >>> import numpy >>> a = numpy.array([1, 2, 3, 4, 5]) >>> a[::-1] array([5, 4, 3, 2, 1]) >>> a[:] = a[::-1] >>> a array([5, 4, 3, 4, 5]) This is a known issue. I'm not sure how easy would it be to arrange the assignment loops so that the overlapping data would be handled correctly. I think that numpy should at least raise a warning if not an error in __setitem__, when the two arrays have the same ancestor (needs walking up the .base links). What's the general opinion on this? Pauli
signature.asc
Description: Digitaalisesti allekirjoitettu viestin osa
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion