[Matrix-SIG] New Behavior for NumPy scalars?

Travis Oliphant Oliphant.Travis@mayo.edu
Fri, 3 Sep 1999 17:50:14 -0500 (CDT)


O.K. I thought I had just gotten used to the old way of having NumPy
return Python scalars whenever a routine ends up with a NumPy scalar (not
necessarily a good idea when trying to keep everything as Floats).

Now, it looks like the math operations on NumPy scalars (rank-0 arrays)
result in NumPy scalars but being upcast to what a Python scalar of the
appropriate type would be.  I don't think this is what is wanted.  If we
are going to keep NumPy scalars as NumPy scalars after math results (I'm
all for this as it would alleviate many of my upcasting problems) we 
should keep them the same type.

Example:

say b = array(3.0,'f')
    a = array(2.0,'f')

It used to be that b-a returned a Python Float with value 1.0

Now b-a returns a NumPy Array of rank 0, with value 1.0 but with type 'd'.
I don't think anyone likes this idea.


The problem is that the __sub__ method of Array returns an Array all of
the time but subtract method returns a Python object for rank-0 results.

My personal solution preference is to not use PyArray_Return for the
ufuncs and let users who really need a scalar do the indexing to get it
from the rank-0 array.  Using PyArray_Return seems like trying to
second-guess the user and leads to these kinds of issues.

Anyone else having any fun with the new NumPy 1.12 beta release?

--Travis