[Numpy-discussion] ravel() in ma/core.py

Christoph T. Weidemann ctw@cogsci.i...
Tue Aug 12 22:00:01 CDT 2008


Hi!

I'm working with a subclass of ndarray and ran into an issue that
seems to be caused by a line in numpy/ma/core.py
The offending line is no. 1837 in version 1.1.0 or 2053 in the latest
SVN version (revision 5635):
r = ndarray.ravel(self._data).view(type(self))

The problem is that my subclass of ndarray has its own implementation
of the ravel method that takes care of some important things before
calling the ndarray.ravel class. Calling ndarray.ravel directly on
this data structure doesn't allow for the necessary house-keeping to
take place and my data structure complains by throwing an exception.I
believe this issue would be solved if the above line instead read:
r = self.ravel()
or alternatively
r = np.ravel(self)
or something along those lines -- can anybody here please take a look
and see if these (or something else) would be a viable alternative
that would cause the subclass's ravel function to be called instead of
ndarray.ravel()?

Thanks,
CTW

PS: I ran into this issue while trying to plot my data with the imshow
function in matplotlib. If vmin and/or vmax are not specified, a
masked array version of the input array is generated in
matplotlib/colors.py in this line:
val = ma.asarray(value).astype(np.float)
Then ma.minimum() and ma.maximum() are called and eventually the line
highlighted above gets executed. I don't know if/why this conversion
to masked arrays is necessary in the matplotlib code, but it seems
pretty clear that the source of the problem is the application of the
ndarray.ravel() method rather than that for the subclass in the line
highlighted above.


More information about the Numpy-discussion mailing list