assigning ma.masked. Strange behavior
import numpy as np import numpy.ma as ma # There is no effect on the following assignment of ma.masked. a1 = ma.arange(10).reshape((2,5)) a1.ravel()[np.array([0,2,2])] = ma.masked # The following works: a1 = ma.arange(10) a1[np.array([0,2,2])] = ma.masked a1.shape = 2,5 -- View this message in context: http://www.nabble.com/assigning-ma.masked.-Strange-behavior-tp24336615p24336... Sent from the Numpy-discussion mailing list archive at Nabble.com.
2009/7/4 Ben Park
: import numpy as np import numpy.ma as ma
# There is no effect on the following assignment of ma.masked. a1 = ma.arange(10).reshape((2,5)) a1.ravel()[np.array([0,2,2])] = ma.masked
In some situations ravel has to return a copy of the data instead of a view. You're assigning ma.masked to elements of the copy, not tot elements of a1.
a1 = ma.arange(10).reshape((2,5)) b = a1.ravel() b[np.array([0,2,2])] = ma.masked b masked_array(data = [-- 1 -- 3 4 5 6 7 8 9], mask = [ True False True False False False False False False False], fill_value = 999999)
a1 masked_array(data = [[0 1 2 3 4] [5 6 7 8 9]], mask = False, fill_value = 999999)
a1.ravel()[np.array([0,2,2])] = ma.masked a1 masked_array(data = [[0 1 2 3 4] [5 6 7 8 9]], mask = False, fill_value = 999999)
Cheers, Scott
participants (2)
-
Ben Park
-
Scott Sinclair