[SciPy-user] array vs matrix, converting code from matlab
david at ar.media.kyoto-u.ac.jp
Thu Apr 20 05:38:53 CDT 2006
Dear numpy users,
I am converting some code from matlab to numpy/scipy, but still a
bit confused by numpy, mostly the array vs matrix issue. Looking at the
scipy website, the matrix type looks the closest to matlab syntax, but I
still have some issues:
- under matlab, everything, including scalar, are matrices in matlab
sense. In python, they are not. So, of I want to handle scalar case in
a function which takes arrays, what should I do ? Having special case
for scalar sounds like a pain, so is asarray/asmatrix the best way to
handle those cases so my function only deal with array types ?
- what is the difference between matrix and array, except syntax ?
If I want to handle both in one function, what is the "best" method ?
Using one type only (for example matrix), and using asmatrix on all
arguments accordingly ?
To convert my matlab code, I was thinking about using asmatrix for
arguments in all my functions, but I am not sure this is really the
"right" way. I was hoping some other people would have some experience
with the same issues, and could give me some general advices
P.S: it would be great to have this kind of information on scipy
website; right now, the scipy for matlab users part is a bit sparse... I
am willing to change this once I understand the problem myself, of course:)
More information about the SciPy-user