[Numpy-discussion] Detect subclass of ndarray

Alan G Isaac aisaac@american....
Sat Mar 24 11:22:36 CDT 2007

>> On Fri, 23 Mar 2007, Charles R Harris apparently wrote: 
>>> 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. 

> On 3/24/07, Alan G Isaac <aisaac@american.edu> wrote: 
>> Why should this output a column? 
>> I would prefer an exception. 
>> Add the axis if you want it: 
>> I*ones(2)[:,None] 
>> works fine. 

On Sat, 24 Mar 2007, Charles R Harris apparently wrote: 
> Because it is mathematically correct. You can't multiply 
> a vector by a 2x2 matrix and get a 1x2 matrix as the 
> result.

I do not understand:
what do you mean mathematically correct?
What is the space on which this operator is being defined?

In my opinion, it is mathematically meaningless.
Forcing meaning into it is a bad idea.

Just because there is a sloppy convention to call n×1 
matrices and 1×n matrices "vectors" does not mean they are 
not 2d.  They are.  That is *why* matrix multiplication is 
defined for them.

As I suggested, the right thing to do when someone attemps 
matrix multiplication with an object that is not 2d is to 
raise an exception.  The wrong thing to do is to pretend 
than an object without an orientation has one: that is
inherently not explicit and will surely bite someone sooner 
or later, probably sooner.

Alan Isaac

More information about the Numpy-discussion mailing list