[Numpy-discussion] [SciPy-user] unique, sort, sortrows

Alan G Isaac aisaac@american....
Mon Jul 28 08:51:47 CDT 2008

David M. Kaplan wrote:
> python appears to be fairly sloppy about how it passes 
> indexing arguments to the __getitem__ method.

I do not generally find the word 'sloppy' to be descriptive
of Python.

> It passes a tuple containing the arguments in all cases 
> except when it has one argument, in which case it just 
> passes that argument.

Well, not quite.  The bracket syntax is for passing a key
(a single object) to __getitem__.

> For example, the following two produce exactly the same 
> call to __getitem__ :
> mgrid[1,2,3] 
> mgrid[(1,2,3)] 

Well, yes.  Note::

     >>> x = 1,2,3
     >>> type(x)
     <type 'tuple'>

In Python it is the commas, not the paretheses,
that is determining the tuple type.

So perhaps the question you raise could be rephrased to
"why does an ndarray (not Python) handle treat
a list 'index' differently than a tuple 'index'?"
I do not know the history of that decision,
but it has been used to provide some additional functionality.

Alan Isaac

More information about the Numpy-discussion mailing list