From: Teemu Rinne <Teemu.R<inne@he...> - 2006-11-27 19:17:38
I downloaded&installed matplotlib 0.87.7 and other binary packages from
pythonmac.org for my new Intel Mac Pro. Then I downloaded and compiled the
latest scipy package. My collection of packages runs ok otherwise but there
seems to be something wrong with pylab/masked array behavior.
This works on my older installations (g5):
from pylab import *
from MA import *
On my Intel Mac Pro, I get:
File "test.py", line 12, in ?
line 106, in swapaxes
return _wrapit(a, 'swapaxes', axis1, axis2)
line 39, in _wrapit
result = getattr(asarray(obj),method)(*args, **kwds)
line 132, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: object __array__ method not producing an array
There seems to be some kind of name space conflict. The line
'a=swapaxes(a,0,1)' works as expected without 'from MA import *'. If I do
'import MA' and use MA.array etc for all operations with masked arrays
everything seems to work fine.
Any ideas where the conflict might be coming from?
University of Helsinki
From: Pierre GM <pgmdevlist@gm...> - 2006-11-27 19:54:30
> Any ideas where the conflict might be coming from?
When you type from MA import *, you overwrite the definition of 'array'. And
surprisingly enough, a masked array in numpy.core.ma is an object
independent of ndarray. Some functions such as swapaxes are not imported by
MA (because they were not implemented for one reason or another): you then
use the regular numpy function, which doesn't know how to deal with these
'masked arrays' objects. (I simplify a bit, here, but the gist is there)
As you've noticed, the best solution is to use
That way, you leave the original numpy namespace alone, and are sure to use
only "MA-approved" functions. But you'll likely gonna have to use MA.sqrt,
MA.log all over your code. And may run into problems with functions that
don't handle masked arrays. Still, it's the cleanest solution (the "from blah
import *" tend to be frowned upon these days anyway).
An alternative solution is to try the new implementation of masked arrays I've
been working on: with this implementation, masked arrays are subclasses of
regular arrays, which simplifies life a lot.The source file is available
Note the disclaimer: it's still a work in progress (even if I use it everyday
and it works fine) and you'll have to modify a line in the matplotlib source
to make it work OK with matplotlib, which is a bit tedious I agree. But it
works. And it's actively maintained.
Hope it helps