[Matrix-SIG] NumPy inconsistency?

Konrad Hinsen hinsen@cnrs-orleans.fr
Mon, 14 Dec 1998 18:40:59 +0100


> Is there a reason why adding a 2-tuple to 2d array is allowed but
> multiplying a 2d array by a 2-tuple isn't? See here:

It seems to me that neither "should" work, i.e. is documented to
work, but addition can be made to work (and it works), whereas
multiplication can't.

The interpreter decides that the operations to be applied are
sequence addition and sequence multiplication. Sequence addition
is unrestricted and the implementation in NumPy accepts any
kind of sequence as argument. But sequence multiplication is
restricted to integer prefactors, which is why you get an
error message.

So in the end the confusion is a consequence of the double status
of arrays as both a number-like type and a sequence type.

Konrad.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                            | E-Mail: hinsen@cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.55.69
Rue Charles Sadron                       | Fax:  +33-2.38.63.15.17
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais
-------------------------------------------------------------------------------