[SciPy-user] Masked array question

Robert Ferrell ferrell@diablotech....
Mon Jun 8 15:11:05 CDT 2009


On Jun 8, 2009, at 11:32 AM, Pierre GM wrote:

>
> On Jun 8, 2009, at 12:59 PM, Robert Ferrell wrote:
>
>> I have a tuple of strings that I want to convert to an array of
>> floats.  Some of the strings are empty, so I thought I could use a
>> masked array to mask out the empty strings.  (In my application,  
>> empty
>> string means no data, so ignore.)
>>
>> I tried:
>>
>> np.ma.masked_array(('1.', ' '), mask=(False, True),  
>> dtype=(np.float32,
>> np.float32))
>
> As indicated by the error message, it's a pb w/ numpy: it doesn't know
> how to process the '' for float. That you're using masked arrays
> unfortunately doesn't change anything to that
> An idea is then to convert your '' to 'NaN' beforehand and use
> np.ma.fix_invalid on the results, or to define a mask as you wanted.

np.ma.fix_invalid() is helpful.  Originally I was wondering if there  
was a way to get masked_array to ignore (not process) the masked out  
entries.

fix_invalid() helps, since I don't have to make up a mask before  
creating the masked_array.

thanks,
-robret



More information about the SciPy-user mailing list