[Numpy-discussion] Handling methods of object-arrays

Robert Kern robert.kern@gmail....
Tue Jan 6 03:19:10 CST 2009

On Tue, Jan 6, 2009 at 03:15, Stéfan van der Walt <stefan@sun.ac.za> wrote:
> Hi all,
> What is the exact protocol for evaluating functions like "real" and
> "imag" on object arrays?
> For example, I'm looking at
> x  = np.array([np.array(3+1j), np.array(4+1j)], dtype=object)
> For which both
> In [4]: x.real
> Out[4]: array([(3+1j), (4+1j)], dtype=object)
> and
> In [6]: np.real(x)
> Out[6]: array([(3+1j), (4+1j)], dtype=object)
> does nothing, so that I have to do
> In [8]: [np.real(e) for e in x]
> Out[8]: [array(3.0), array(4.0)]
> or [e.real for e in x].
> Would it make sense make np.real aware of the above scenario?

Methods like ndarray.sin() check for e.sin(), so a case could
certainly be made that ndarray.real should check for e.real .

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the Numpy-discussion mailing list