[Numpy-discussion] Detect subclass of ndarray

Charles R Harris charlesr.harris@gmail....
Sat Mar 24 00:39:35 CDT 2007


On 3/23/07, Anne Archibald <peridot.faceted@gmail.com> wrote:
>
> On 23/03/07, Charles R Harris <charlesr.harris@gmail.com> wrote:
> > Anyone,
> >
> > What is the easiest way to detect in python/C if an object is a subclass
> of
> > ndarray?
>
> Um, how about isinstance or issubclass? (if you want strictness you
> can look at whether x.__class__ is zeros(1).__class__)


What I am trying to do is figure out the easiest way to fix up matrix
multiplies so they work properly. For instance, the following gives the
wrong result:

In [15]: I = matrix(eye(2))

In [16]: I*ones(2)
Out[16]: matrix([[ 1.,  1.]])

where the output should be a column vector. In order to do that, I need to
reshape the rh multiplicand before __mul__ calls the dot function. There is
also this problem

In [17]: I*[[1],[1]]
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most recent
call last)

/home/charris/<ipython console>

TypeError: can't multiply sequence by non-int

A similar multiplication on the left works just fine.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070323/7583c429/attachment-0001.html 


More information about the Numpy-discussion mailing list