[SciPy-User] Matrix indexing and updating

Anne Archibald aarchiba at physics.mcgill.ca
Tue Nov 2 12:57:45 EDT 2010


On 1 November 2010 06:43, Luca Manini <manini.luca at tiscali.it> wrote:
>>>>>> "Emanuele" == Emanuele Olivetti <emanuele at 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