[SciPy-User] Matrix indexing and updating

Anne Archibald aarchiba@physics.mcgill...
Tue Nov 2 11:57:45 CDT 2010


On 1 November 2010 06:43, Luca Manini <manini.luca@tiscali.it> wrote:
>>>>>> "Emanuele" == Emanuele Olivetti <emanuele@relativita.com> writes:
>
>    Emanuele> Hi Luca, If I understand you problem correctly, maybe
>    Emanuele> this example can help you:
>
>    It helps a little, but:
>
>    1) you are using numpy.ndarray instead of scipy.matrix.  I have
>       not grasped the difference yet, apart for the annoying fact
>       that a 1xN matrix is not a vector and still has two indices
>       (and that makes the code less "explicit").

That's the difference between matrices and ndarrays: matrices are
always two-dimensional no matter what you do to them. They also change
the * operator so that it's matrix multiplication rather than
elementwise (for ndarrays use "dot"). If this annoys you, just use
ndarrays. They're better-supported and more consistent.

My own recommendation is not to use matrices, ever, for anything. But
others differ.

Anne


More information about the SciPy-User mailing list