Numpy-scalars vs Numpy 0-d arrays: copy or not copy?

Travis Oliphant oliphant at
Fri Oct 20 18:12:50 CDT 2006

Sebastien Bardeau wrote:

>>One possible solution (there can be more) is using ndarray:
>>In [47]: a=numpy.array([1,2,3], dtype="i4")
>>In [48]: n=1    # the position that you want to share
>>In [49]: b=numpy.ndarray(buffer=a[n:n+1], shape=(), dtype="i4")
>Ok thanks. Actually that was also the solution I found. But this is much 
>more complicated when arrays are N dimensional with N>1, and above all 
>if user asks for a slice in one or more dimension. Here is how I 
>redefine the __getitem__ method for my arrays. Remember that the goal is 
>to return a 0-d array rather than a numpy.scalar when I extract a single 
>element out of a N-dimensional (N>=1) array:

How about this.  To get the i,j,k,l element



Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo

More information about the Numpy-discussion mailing list