Numpy-scalars vs Numpy 0-d arrays: copy or not copy?
Travis Oliphant
oliphant at ee.byu.edu
Fri Oct 20 19:12:50 EDT 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
a[i:i+1,j:j+1,k:k+1,l:l+1].squeeze()
-Travis
-------------------------------------------------------------------------
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
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
More information about the NumPy-Discussion
mailing list