Re: [Numpy-discussion] Question on numpy.ma.masked_values
Gökhan, By default, the mask of a MaskedArray is set to the special value `np.ma.nomask`. In other terms:: np.ma.array(...) = np.ma.array(..., mask=np.ma.nomask) In practice, np.ma.nomask lets us quickly check whether a MaskedArray has a masked value : if its .mask is np.ma.nomask, then no masked value, otherwise it's a full boolean array and we can use any. If you want to create a MaskedArray w/ a full boolean mask, just use:: np.ma.array(..., mask=False) In that case, the mask is automatically created as a boolean array with the same shape as the data, with False everywhere. If you used True, the mask would be full of True... Now, just to be clear, you'd want 'np.ma.masked_values(...,shrink=False) to create a maked array w/ a full boolean mask by default, right ? On 3/15/12, Gökhan Sever gokhanse...@gmail.com wrote: Submitted the ticket at http://projects.scipy.org/numpy/ticket/2082 On Thu, Mar 15, 2012 at 1:24 PM, Gökhan Sever gokhanse...@gmail.com wrote: On Thu, Mar 15, 2012 at 1:12 PM, Pierre GM pgmdevl...@gmail.com wrote: Ciao Gökhan, AFAIR, shrink is used only to force a collapse of a mask full of False, not to force the creation of such a mask. Now, it should work as you expected, meaning that it needs to be fixed. Could you open a ticket? And put me in copy, just in case. Anyhow: Your trick is a tad dangerous, as it erases the previous mask. I'd prefer to create x w/ a full mask, then use masked_values w/ shrink=False... Now, if you're sure there's x= no masked values, go for it. Cheers This condition checking should make it stronger: I7 x = np.array([1, 1.1, 2, 1.1, 3]) I8 y = np.ma.masked_values(x, 1.5) I9 if y.mask == False: y.mask = np.zeros(len(x), dtype=np.bool)*True ...: I10 y.mask O10 array([False, False, False, False, False], dtype=bool) I11 y O11 masked_array(data = [1.0 1.1 2.0 1.1 3.0], mask = [False False False False False], fill_value = 1.5) How do you create x w/ a full mask? -- Gökhan -- Gökhan ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Question on numpy.ma.masked_values
Yes, that's the behaviour that I expect setting the 'shrink' keyword to 'False' Now, just to be clear, you'd want 'np.ma.masked_values(...,shrink=False) to create a maked array w/ a full boolean mask by default, right ? ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Question on numpy.ma.masked_values
On Thu, Mar 15, 2012 at 12:56 PM, Gökhan Sever gokhanse...@gmail.comwrote: If not so, how can I return a set of False values if my masking condition is not met? Self-answer: I can force the mask to be filled with False's, however unsure if this is a safe operation. I50 x = np.array([1, 1.1, 2, 1.1, 3]) I51 y = np.ma.masked_values(x, 1.5, shrink=0) I52 y O52 masked_array(data = [1.0 1.1 2.0 1.1 3.0], mask = False, fill_value = 1.5) I53 y.mask = np.zeros(len(x), dtype=np.bool)*True I54 y O54 masked_array(data = [1.0 1.1 2.0 1.1 3.0], mask = [False False False False False], fill_value = 1.5) ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Question on numpy.ma.masked_values
Ciao Gökhan, AFAIR, shrink is used only to force a collapse of a mask full of False, not to force the creation of such a mask. Now, it should work as you expected, meaning that it needs to be fixed. Could you open a ticket? And put me in copy, just in case. Anyhow: Your trick is a tad dangerous, as it erases the previous mask. I'd prefer to create x w/ a full mask, then use masked_values w/ shrink=False... Now, if you're sure there's no masked values, go for it. Cheers On Mar 15, 2012 7:56 PM, Gökhan Sever gokhanse...@gmail.com wrote: Hello, From the masked_values() documentation - http://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.masked_values.html I10 np.ma.masked_values(x, 1.5) O10 masked_array(data = [ 1. 1.1 2. 1.1 3. ], mask = False, fill_value = 1.5) I12 np.ma.masked_values(x, 1.5, shrink=False) O12 masked_array(data = [ 1. 1.1 2. 1.1 3. ], mask = False, fill_value = 1.5) Shouldn't setting the 'shrink' to False return an array of False values for the mask field? If not so, how can I return a set of False values if my masking condition is not met? Using: I16 np.__version__ O16 '2.0.0.dev-7e202a2' Thanks. -- Gökhan ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Question on numpy.ma.masked_values
On Thu, Mar 15, 2012 at 1:12 PM, Pierre GM pgmdevl...@gmail.com wrote: Ciao Gökhan, AFAIR, shrink is used only to force a collapse of a mask full of False, not to force the creation of such a mask. Now, it should work as you expected, meaning that it needs to be fixed. Could you open a ticket? And put me in copy, just in case. Anyhow: Your trick is a tad dangerous, as it erases the previous mask. I'd prefer to create x w/ a full mask, then use masked_values w/ shrink=False... Now, if you're sure there's x= no masked values, go for it. Cheers This condition checking should make it stronger: I7 x = np.array([1, 1.1, 2, 1.1, 3]) I8 y = np.ma.masked_values(x, 1.5) I9 if y.mask == False: y.mask = np.zeros(len(x), dtype=np.bool)*True ...: I10 y.mask O10 array([False, False, False, False, False], dtype=bool) I11 y O11 masked_array(data = [1.0 1.1 2.0 1.1 3.0], mask = [False False False False False], fill_value = 1.5) How do you create x w/ a full mask? -- Gökhan ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Question on numpy.ma.masked_values
Submitted the ticket at http://projects.scipy.org/numpy/ticket/2082 On Thu, Mar 15, 2012 at 1:24 PM, Gökhan Sever gokhanse...@gmail.com wrote: On Thu, Mar 15, 2012 at 1:12 PM, Pierre GM pgmdevl...@gmail.com wrote: Ciao Gökhan, AFAIR, shrink is used only to force a collapse of a mask full of False, not to force the creation of such a mask. Now, it should work as you expected, meaning that it needs to be fixed. Could you open a ticket? And put me in copy, just in case. Anyhow: Your trick is a tad dangerous, as it erases the previous mask. I'd prefer to create x w/ a full mask, then use masked_values w/ shrink=False... Now, if you're sure there's x= no masked values, go for it. Cheers This condition checking should make it stronger: I7 x = np.array([1, 1.1, 2, 1.1, 3]) I8 y = np.ma.masked_values(x, 1.5) I9 if y.mask == False: y.mask = np.zeros(len(x), dtype=np.bool)*True ...: I10 y.mask O10 array([False, False, False, False, False], dtype=bool) I11 y O11 masked_array(data = [1.0 1.1 2.0 1.1 3.0], mask = [False False False False False], fill_value = 1.5) How do you create x w/ a full mask? -- Gökhan -- Gökhan ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion