[Matrix-SIG] New Behavior for NumPy scalars?

Konrad Hinsen hinsen@cnrs-orleans.fr
Tue, 7 Sep 1999 12:05:31 +0200


> > and what works well for the vast majority of applications.
> 
> Hmm.  Unless you are trying to actually use the single precision
> datatypes.  Then, you have to be extremely careful not to lose precision
> because your NumPy arrays are always getting converted to Python scalars.

Right. And I wouldn't mind disabling the conversion to scalars for
single-precision rank-0 arrays. After all, there are no single-precision
scalars, so there's a good reason for not doing that conversion.
And beginners are unlikely to fall into this trap.

Does this sound like a useful compromise?

> I'd do it.  I think the reason is the same as why is it necessary to have
> both lists and NumPy arrays for the beginning user.

But that's easy, they have different properties. Scalars and rank-0
arrays, at least those that correspond to Python scalar types, are
expected to behave absolutely identically.

> >     a = Numeric.zeros((3,))
> >     a[0] = 1
> >     ...
> >     if a[0] == 1:
> >        ...
> > would do something very unexpected.
> > 
> 
> This would be confusing for beginners it is agreed.  But there are always

And not only that: the correct version of the test in the example above
looks awful. And a test that would work for any sequence object a would
become somewhere between incredibly messy and impossible.

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
-------------------------------------------------------------------------------