Re: [Numpy-discussion] A case for rank-0 arrays
by Sasha other posts by this author
Feb 24 2006 6:25AM messages near this date
Re: [Numpy-discussion] A case for rank-0 arrays
|
Re: [Numpy-discussion] A case for rank-0 arrays
On 2/24/06, Travis Oliphant <oliphant.travis@[...].org> wrote:
> Sasha wrote:
> ...
> >>>>type(array(2)*2)
> >>>>
> >>>>
> ><type 'int32scalar'>
> >
> >I believe it should result in a rank-0 array instead.
> >
> >
> Can you be more precise about when rank-0 array should be returned and
> when scalars should be?
A simple rule could be that unary functions that don't change the rank
when operating on higer dimensional arrays should not change the type
(scalar vs. array) of the dimensionless objects. For binary operations
such as in the example above, the situation is less clear, but in this
case an analogy with functions helps. Multiplication between a
function f(...) and a scalar 2 is naturally defined as a function
(2*f)(...) = 2*f(...), where ... stands for any number of arguments
including zero. The scalars should be returned when an operation
involves extracting an element, or evaluation of a function. This
includes indexing with a complete set of indices (and no ellipsis) and
reduce operations over all elements (more on that later.)
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@[...].net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Thread:
Sasha
Francesc Altet
Francesc Altet
Colin J. Williams
Travis Oliphant
Sasha
Francesc Altet
Sasha
Travis Oliphant
Sasha
Francesc Altet
|