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] rank-0 arrays
by Konrad Hinsen other posts by this author
Sep 15 2002 7:40PM messages near this date
RE: [Numpy-discussion] rank-0 arrays | Re: [Numpy-discussion] rank-0 arrays
>  > And it should fail, because a rank-0 array is not a sequence, so it
>  > doesn't have a length.
>  
>  I disagree. You should not have to write special code to check for a
>  specific case.  It breaks one of the beauties of Numeric -- i.e. you can

It is not a specific case, more like a specific value (for the rank).
1/a fails for a == 0, should that be changed as well?

Let's examine some equivalent code pieces:

- len(a) == a.shape[0]
  the second fails for rank 0, so the first one should fail as well

- for i in range(len(a)):  print a[i]
  works for all sequences. If len(a) doesn't fail (and I assume it would
  then return 1), a[1] shouldn't fail either.

- len(a) == len(list(a))
  for all sequences a. Should list(a) return [a] for a rank-0 array?
  For a scalar it fails.

Actually this might be an argument for not having rank-0 arrays at all.
Arrays are multidimensional sequences, but rank-0 arrays aren't.

>  returns its length along its "first" axis.  This will always be 1.  It
>  allows for generic code.

Then please give an example where this genericity would be useful.

>  On this note:
>  I do not see the benefit of making a scalar type object that is separate
>  for 0d arrays.  It seems to remove instead of enhance capabilities.
>  What does a scalar object buy that simply using 0d arrays for that
>  purpose does not?

Compatibility, for example the ability to index a sequence with an
element of an integer array. Also consistency with other Python
sequence types. For example,

   [a][0] == a

so one would expect also

   array([a])[0] == a

but this would not be fully true if the left-hand side is a rank-0
array.

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

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