[Numpy-discussion] how to use masked arrays
Pierre GM
pgmdevlist@gmail....
Wed May 14 12:33:34 CDT 2008
On Wednesday 14 May 2008 13:19:55 Eric Firing wrote:
> Pierre GM wrote:
> > (almost) equivalent [1]:
> >>>> mydata._data
> >>>> mydata.view(np.ndarray)
>
> Shouldn't the former be discouraged, on the grounds that a leading
> underscore, by Python convention, indicates an attribute that is not
> part of the public API, but is instead part of the potentially
> changeable implementation?
Eric,
* Please keep the note [1] in mind: the two commands are NOT equivalent: the
former outputs a subclass of ndarray (when appropriate), the latter a regular
ndarray.
* You can use mydata.data to achieve the same result as mydata._data. In
practice, both _data and data are properties, without a fset method and a
with fget= lambda x:x.view(x._baseclass). I'm not very comfortable with
using .data myself, it looks a bit awkward (personal taste), and it may let a
user think that the readbuffer object is accessed (when in fact, it's
mydata.data.data...)
* The syntax ._data is required for backwards compatibility (that was the data
portion of the old MaskedArray object). So is ._mask
* You can also use the getdata(mydata) function: it returns the ._data part of
a masked array or the argument as a ndarray, depending which is available.
More information about the Numpy-discussion
mailing list