[Numpy-discussion] array vs. matrix for matlab-compatible stuff

Sven Schreiber svetosch at gmx.net
Thu Jan 19 04:42:09 CST 2006


Travis Oliphant schrieb:
> Sven Schreiber wrote:
> 
>> Hi,
>> I've spent a couple of weeks with scipy/numpy and the old-to-new
>> transition; now that the transition is over (?) but some confusion is
>> remaining (on my side) I feel the need to ask a basic question about
>> matlab compatibility in terms of matrix (linear algebra) programming.
>>
>> Take "eye" and "identity" for example; given that "eye" supposedly
>> exists to facilitate transiton from matlab to numpy/scipy (correct?),
>> I expected eye to be/return a matrix.
> 
> 
> Historical is the only reason.  Numeric always returned an array for eye
> not a matrix.  We could return a matrix without difficulty especially if
> we put an eye --> identity transition in convertcode.py
> 

I see, thanks for the quick answer. So wouldn't it be a good idea to have all the specifically
matrix-related stuff (afaics, things in numpy/lib/twodim_base.py) return matrices?

It seems my question (or misunderstanding) has a broader scope: Coming from matrix languages, I'm
glad about short notations like A.I or A*B representing standard matrix operations. Much easier than
linalg.inverse(A) or matrixmultiply(A,B). However, many matrix functions (decompositions etc.) seem
to return arrays instead of matrices, even if you feed them matrices (is this assumption correct?).
So you have to use mat(returned-result) again and again to be able to do return-result.I afterwards,
which seems clumsy. So what's the best strategy here?

I'm aware that this is very much a basic/newbie question, so a pointer to the answer(s) would also
be very welcome. If you think I should purchase the numpy-book to get the authorative answer, feel
free to tell me so (but only if it really has the answer ;-)

Thanks for your help,
Sven





More information about the Numpy-discussion mailing list