[SciPy-user] Masked array question
Mon Jun 8 11:59:41 CDT 2009
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.)
np.ma.masked_array(('1.', ' '), mask=(False, True), dtype=(np.float32,
but that doesn't work. It returns
core.py in __new__(cls, data, mask, dtype, copy, subok, ndmin,
fill_value, keep_mask, hard_mask, flag, shrink, **options)
1257 shrink = flag
1258 # Process data............
-> 1259 _data = np.array(data, dtype=dtype, copy=copy,
1260 _baseclass = getattr(data, '_baseclass', type(_data))
1261 # Check that we'ew not erasing the mask..........
<type 'exceptions.ValueError'>: setting an array element with a
Is there a way to do this (easily)? What I can do is first convert
the strings to floats, and set the empty strings to some fill value,
and then pass that to masked_array. Is that the best solution? Or is
there some method that I've missed?
More information about the SciPy-user