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] Behavior of array scalars
by Sasha other posts by this author
Feb 17 2006 4:31PM messages near this date
Re: [Numpy-discussion] Behavior of array scalars | Re: [Numpy-discussion] Behavior of array scalars
Sorry for a truncated post.  Here is what I intended.

On 2/17/06, Travis Oliphant <oliphant@[...].edu>  wrote:
>  NumPy (starting with Numeric) has always had this love-hate relationship
>  with zero-dimensional arrays.  We use them internally to simplify the
>  code, but try not to expose them to the user.  Ultimately, we couldn't
>  figure out how to do that cleanly and so we have the current compromise
>  situation where 0-d arrays are available but treated as second-class
>  citizens.   Thus, we still get funny behavior in certain circumstances.

It would be nice to collect the motivations behind the current state
of affairs with rank-0 arrays in one place.  Due to the "hard-hat"
nature of the issue, I would suggest to do it at
http://projects.scipy.org/scipy/numpy/wiki/ZeroRankArray .

Travis' Numeric3 design document actually leaves the issue open

"""
What does single element indexing return? Scalars or rank-0 arrays?
Right now, a scalar is returned if there is a direct map to a Python
type, otherwise a rank-0 array (Numeric scalar) is returned. But, in
problems which reduce to an array of arbitrary size, this can lead to
a lot of code that basically just checks to see if the object is a
scalar. There are two ways I can see to solve this: 1) always return
rank-0 arrays (never convert to Python scalars) and 2) always use
special functions (like alen) that handle Python scalars correctly.
I'm open to both ideas, but probably prefer #1 (never convert to
Python scalars) unless requested.
""" <http://web.archive.org/web/20050207124620/www.scipy.org/wikis/numdesign/> 

I can think of two compelling reasons in favor of scalar array types:

1. Rank-0 arrays cannot be used as indices to tuples.
2. Rank-0 arrays cannot be used as keys in dicts.

Neither of these resons is future proof.  It looks like python 2.5
will introduce __index__ slot that will fix #1 and #2 is probably
better solved by introduction of "frozen" ndarray.

In any case I will collect all these thoughts on the ZeroRankArray
page unless I hear that this belongs to the main wiki.


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@[...].net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Thread:
Christopher Barker
Travis Oliphant
Sasha
Travis Oliphant
Christopher Barker
Sasha
Travis Oliphant
David M. Cooke
Sasha
Travis Oliphant
Travis Oliphant
Sasha
Travis Oliphant
Sasha
Alexander Belopolsky
Sasha

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