Re: [Numpy-discussion] rank-0 arrays
by Konrad Hinsen other posts by this author
Sep 15 2002 10:12AM messages near this date
RE: [Numpy-discussion] rank-0 arrays
|
RE: [Numpy-discussion] rank-0 arrays
"eric jones" <eric@[...].com> writes:
> Reductions and indexing return different types based on the number of
> dimensions of the input array:
>
> >>> b = sum(a)
> >>> l = len(b) # or whatever
>
> This code works happily if "a" is 2 or more dimensions, but will fail if
> it is 1d because the sum(a) will return a scalar in this case. To write
And it should fail, because a rank-0 array is not a sequence, so it
doesn't have a length.
But there are valid examples in which it would be nice if scalars
were arrays (but probably if *all* scalars supported array operations,
not just those that were generated by indexing from arrays):
- a.shape should return () for a scalar (and (len(a),) for any
sequence type)
- a.astype(N.Float) should also work for scalars
Similarly, it would be nice if complex operations (real/imaginary
part) would work on integers and floats.
There's one more annoying difference between scalars and arrays of
any rank which I think should be removed in numarray:
> >> 3 % -2
-1
> >> array(3) % 2
1
> >> fmod(3, -2)
1.0
I.e. the mod operation uses fmod() for arrays, but different rules
for standard Python numbers.
Konrad.
--
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hinsen@[...].fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24
Rue Charles Sadron | Fax: +33-2.38.63.15.17
45071 Orleans Cedex 2 | Deutsch/Esperanto/English/
France | Nederlands/Francais
-------------------------------------------------------------------------------
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@[...].net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Thread:
Perry Greenfield
Travis Oliphant
Pearu Peterson
Konrad Hinsen
Perry Greenfield
Todd Miller
Pearu Peterson
Konrad Hinsen
Travis Oliphant
Konrad Hinsen
Perry Greenfield
Travis Oliphant
Tim Hochberg
Chris Barker
Konrad Hinsen
Perry Greenfield
Travis Oliphant
Pearu Peterson
Tim Hochberg
Perry Greenfield
Konrad Hinsen
Perry Greenfield
eric jones
Konrad Hinsen
eric jones
Konrad Hinsen
Tim Hochberg
Tim Hochberg
Paul F Dubois
Scott Gilbert
Konrad Hinsen
|