ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> numpy-discussion
numpy-discussion
Re: [Numpy-discussion] A case for rank-0 arrays
by Francesc Altet other posts by this author
Feb 24 2006 1:01AM messages near this date
[Numpy-discussion] A case for rank-0 arrays | Re: [Numpy-discussion] A case for rank-0 arrays
A Dissabte 18 Febrer 2006 20:49, Sasha va escriure:
>  PROPOSALS
>  ==========
> 
>  Here are three suggestions:
> 
>  1. Probably the most controversial question is what getitem should
>  return. I believe that most of the confusion comes from the fact that
>  the same syntax implements two different operations: indexing and
>  projection (for the lack of better name).  Using the analogy between
>  ndarrays and functions, indexing is just the application of the
>  function to its arguments and projection is the function projection
>  ((f, x) -> lambda (*args): f(x, *args)).
> 
>  The problem is that the same syntax results in different operations
>  depending on the rank of the array.
> 
>  Let
> 
>  >>> x = ones((2,2))
>  >>> y = ones(2)
> 
>  then x[1] is projection and type(x[1]) is ndarray, but y[1] is
>  indexing and type(y[1]) is int32.  Similarly, y[1,...] is indexing,
>  while x[1,...] is projection.
> 
>  I propose to change numpy rules so that if ellipsis is present inside
>  [], the operation is always projection and both y[1,...] and
>  x[1,1,...] return zero-rank arrays.  Note that I have previously
>  rejected Francesc's idea that x[...] and x[()] should have different
>  meaning for zero-rank arrays.  I was wrong.

+1 (if I want to be consequent ;-)

I guess that this would imply that:

In [19]: z=numpy.array(1)

In [20]: type(z[()])
Out[20]: <type 'int32scalar'> 

In [21]: type(z[...])
Out[21]: <type 'numpy.ndarray'> 

isn't it?

>  2. Another source of ambiguity is the various "reduce" operations such
>  as sum or max.  Using the previous example, type(x.sum(axis=0)) is
>  ndarray, but type(y.sum(axis=0)) is int32.  I propose two changes:
> 
>     a. Make x.sum(axis)  return ndarray unless axis is None, making
>  type(y.sum(axis=0)) is ndarray true in the example.
> 
>     b. Allow axis to be a sequence of ints and make
>  x.sum(axis=range(rank(x))) return rank-0 array according to the rule
>  2.a above.
> 
>     c. Make x.sum() raise an error for rank-0 arrays and scalars, but
>  allow x.sum(axis=()) to return x.  This will make numpy sum consistent
>  with the built-in sum that does not work on scalars.

Well, to say the truth, I've not a strong opinion on this one (this is
why I "mostly" supported your proposal ;-), but I think that if Travis
has reasons to oppose to it, we should listen to him.

>  3. This is a really small change currently
>  I propose to make shape=() valid in ndarray constructor.

+1

Cheers,

-- 
> 0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"



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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved