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 Perry Greenfield other posts by this author
Sep 13 2002 2:05PM messages near this date
Re: [Numpy-discussion] rank-0 arrays | Re: [Numpy-discussion] rank-0 arrays
Konrad Hinsen writes:
> 
>  Pearu Peterson <pearu@[...].ee> writes:
> 
>  > I think it would be confusing if the result of repr would be `2' and not
>  > `array(2)' because 2 and array(2) are not equivalent in all usages
>  > but it should be clear from repr results as a first way to learn more
>  > about the objects.
> 
>  I agree. There will already be some inevitable confusion with both
>  rank-0 arrays and scalars around, with similar but not identical
>  behaviour. Rank-0 arrays shouldn't make it worse by using camouflage.
> 
I also agree that having repr hide the fact that it is an array is
a bad thing. But do you find getting "array(2)" when indexing
a single item acceptable when working interactively? I agree that
displayhook is probably the best way of altering this behavior if
a user desires (perhaps we will provide a module function to do so, but
not enable it by default).

>  >
>  > Could array.__getitem_ and __getslice__ detect if their argument is
>  > an array and skip using Python objects when iterating over indices?
> 
>  Of course they know that they are indexing an array, they are
>  defined at the level of the array class/type. However, they cannot
>  detect an iteration as opposed to a single item access.
> 
I don't know that it is desirable either to have iteration
return different kinds of objects than explicit indexing, even
if possible. Do we really want

for val in x:
    ...

to use scalars while

for i in range(len(x)):
    val = x[i]
    ...

uses rank-0 arrays? I'm inclined not to have different behavior for
what seems like identical iteration.

>  I don't know if this efficiency problem could be important in
>  practice, probably only practice can tell. I have no idea how many
>  single-item indexing operations into arrays occur in my code, this is
>  not something I worried about when writing it.
> 
>  If there will be scalar and rank-0 array returning variants of
>  indexing anyway, then I suppose that changing the index syntax
>  to one or the other is not a big effort. So my suggestion is to
>  make a test release and see what the reactions are.
> 
That is our plan (hence the reference to "experimental"), but I
wanted to see if there were strong feelings on this before doing so.

Perry



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