Changes between Version 3 and Version 4 of ZeroRankArray

Show
Ignore:
Timestamp:
01/10/06 09:57:41 (7 years ago)
Author:
sasha
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ZeroRankArray

    v3 v4  
    1919 
    2020=== Ellipsis and empty tuple === 
     21Sasha started a [http://www.scipy.net/pipermail/scipy-dev/2006-January/004971.html discussion] on scipy-dev 
     22with the folowing proposal: 
     23{{{ 
     24... it may be reasonable to allow a[...].  This way 
     25ellipsis can be interpereted as any number of  ":"s including zero.  
     26Another subscript operation that makes sense for scalars would be 
     27a[...,newaxis] or even a[{newaxis, }* ..., {newaxis,}*], where  
     28{newaxis,}* stands for any number of comma-separated newaxis tokens.  
     29This will allow one to use ellipsis in generic code that would work on 
     30any numpy type.  
     31}}} 
     32The idea to allow increasing the rank of zero-rank arrays with [..., newaxis] was originally 
     33[http://www.scipy.org/wikis/numdesign/ proposed] by Sebastien. 
     34 
     35[http://www.carabos.com/ Francesc Altet] [http://www.scipy.net/pipermail/scipy-dev/2006-January/005022.html supported] 
     36the idea of [...] on zero-rank arrays and suggested that [()] be supported as well. 
     37 
     38Francesc's proposal was: 
     39{{{ 
     40In [65]: type(numpy.array(0)[...]) 
     41Out[65]: <type 'numpy.ndarray'> 
     42 
     43In [66]: type(numpy.array(0)[()])   # Indexing a la numarray 
     44Out[66]: <type 'int32_arrtype'> 
     45 
     46In [67]: type(numpy.array(0).item())  # already works 
     47Out[67]: <type 'int'> 
     48}}} 
     49 
     50There is a consensus that for a zero-rank array x, both x[...] and x[()] should be valid, but the question 
     51remains on what should be the type of the result - zero rank ndarray or x.dtype? 
     52 
     53(Sasha) First, whatever choice is made for x[...] and x[()] they should be the same because ... is just syntactic 
     54sugar for "as many : as necessary", which in the case of zero rank leads to ... = (:,)*0 = ().  Second, rank zero 
     55arrays and numpy scalar types are interchangeable within numpy, but numpy scalars can be use in some python constructs 
     56where ndarrays can't.  For example: 
     57{{{ 
     58>>> (1,)[array(0)] 
     59Traceback (most recent call last): 
     60  File "<stdin>", line 1, in ? 
     61TypeError: tuple indices must be integers 
     62>>> (1,)[int32(0)] 
     631 
     64}}} 
     65Since most if not all numpy function automatically convert zero-rank arrays to scalars on return, there is no reason for 
     66[...] and [()] operations to be different. 
     67 
    2168 
    2269=== Increasing rank with newaxis === 
     70 
     71more to come