[Numpy-discussion] Matlab page on scipy wiki

Colin J. Williams cjw at sympatico.ca
Fri Feb 10 07:14:07 CST 2006


Alan G Isaac wrote:

>On Fri, 10 Feb 2006, Stefan van der Walt apparently wrote: 
>  
>
>>In Octave that would be 
>>[1, 0, 1:4, 0, 1] 
>>Using numpy we currently do 
>>concatenate([[1, 0], arange(1,5), [0, 1]]) or 
>>vstack(...) 
>>    
>>
>
>numpy.r_[1,0,range(1,5),0,1]
>
>fwiw,
>Alan Isaac
>  
>
This seems to be a neat idea but not in the usual Python style.

 >>> help(numpy.r_)
Help on concatenator in module numpy.lib.index_tricks object:

class concatenator(__builtin__.object)
 |  Translates slice objects to concatenation along an axis.
 | 
 |  Methods defined here:
 | 
 |  __getitem__(self, key)
 | 
 |  __getslice__(self, i, j)
 | 
 |  __init__(self, axis=0, matrix=False)
 | 
 |  __len__(self)
 | 
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 | 
 |  __dict__ = <dictproxy object>
 |      dictionary for instance variables (if defined)
 | 
 |  __weakref__ = <attribute '__weakref__' of 'concatenator' objects>
 |      list of weak references to the object (if defined)

The help refers to concatenator, presumably r_ is a synonym, but that 
name is not
available to the user:
 >>> numpy.concatenator
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
AttributeError: 'module' object has no attribute 'concatenator'
 >>>

If r_ is a class, couldn't it have have a more mnemonic name and, in the 
usual
Python style, start with an upper case letter?

help(numpy.r_.__init__)
Help on method __init__ in module numpy.lib.index_tricks:

__init__(self, axis=0, matrix=False) unbound 
numpy.lib.index_tricks.concatenator method

 >>>

Colin W.




More information about the Numpy-discussion mailing list