[SciPy-user] Masked arrays with dtype=object: elements get wrapped in 0D arrays

Jouni K. Seppänen jks at iki.fi
Tue Jan 9 12:12:48 CST 2007


Pierre GM <pgmdevlist at gmail.com> writes:

> In the meanwhile: what are you trying to do ? There should be some kind of 
> workaround.

I have a csv file containing strings, floating-point numbers,
integers, and empty cells (denoting missing data; this is why I want
to use masked arrays). I read it using the standard csv module, which
always returns just strings. I convert the result into a masked array
with dtype=object and iterate through the array, casting anything that
looks like an int or a float into the appropriate data type, and
setting the mask at the locations where the value is the empty string.
Each column in the file is supposed to contain values of just one
type, so I tried to check this, and was surprised to find that each
number is of type numpy.ndarray.

I suppose the simplest workaround is to fix the types and masks in the
lists returned by csv.reader before making the data into an array.

-- 
Jouni K. Seppänen
http://www.iki.fi/jks



More information about the SciPy-user mailing list