From: Travis O. <oli...@ee...> - 2006-10-20 23:13:04
|
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 |