Re: [Numpy-discussion] Numpy-scalars vs Numpy 0-d arrays: copy or not copy?

2006-10-21 Thread Lisandro Dalcin
On 10/20/06, Travis Oliphant <[EMAIL PROTECTED]> wrote: > > 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 I think all this can be condensed in a method call or similar mehcanism, natively provided by ndarray type. Or should this be seen as a speci

Re: [Numpy-discussion] Numpy-scalars vs Numpy 0-d arrays: copy or not copy?

2006-10-20 Thread Travis Oliphant
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

Re: [Numpy-discussion] Numpy-scalars vs Numpy 0-d arrays: copy or not copy?

2006-10-20 Thread Tim Hochberg
Sebastien Bardeau wrote: > Ooops sorry there was two mistakes with the 'hasslice' flag. This seems > now to work for me. > > [SNIP code] That looks overly complicated. I believe that this (minimally tested in a slightly different setting) or some variation should work: return self[...,newaxi

Re: [Numpy-discussion] Numpy-scalars vs Numpy 0-d arrays: copy or not copy?

2006-10-20 Thread Sebastien Bardeau
Ooops sorry there was two mistakes with the 'hasslice' flag. This seems now to work for me. def __getitem__(self,index): # Index may be either an int or a tuple # Index length: if type(index) == int: # A single element through first dimension ilen = 1 index = (ind

Re: [Numpy-discussion] Numpy-scalars vs Numpy 0-d arrays: copy or not copy?

2006-10-20 Thread Tim Hochberg
Francesc Altet wrote: > A Divendres 20 Octubre 2006 11:42, Sebastien Bardeau va escriure: > [snip] > >> I can understand that numpy.scalars do not provide inplace operations >> (like Python standard scalars, they are immutable), so I'd like to use >> >> 0-d Numpy.ndarrays. But: >> >>> d = numpy

Re: [Numpy-discussion] Numpy-scalars vs Numpy 0-d arrays: copy or not copy?

2006-10-20 Thread Sebastien Bardeau
> 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 t

Re: [Numpy-discussion] Numpy-scalars vs Numpy 0-d arrays: copy or not copy?

2006-10-20 Thread Stefan van der Walt
On Fri, Oct 20, 2006 at 11:42:26AM +0200, Sebastien Bardeau wrote: > >>> a = numpy.array((1,2,3)) > >>> b = a[:2] Here you index by a slice. > >>> c = a[2] Whereas here you index by a scalar. So you want to do b = a[[2]] b += 1 or in the general case b = a[slice(2,3)] b += 1 Regards Stéf

Re: [Numpy-discussion] Numpy-scalars vs Numpy 0-d arrays: copy or not copy?

2006-10-20 Thread Francesc Altet
A Divendres 20 Octubre 2006 11:42, Sebastien Bardeau va escriure: [snip] > I can understand that numpy.scalars do not provide inplace operations > (like Python standard scalars, they are immutable), so I'd like to use > > 0-d Numpy.ndarrays. But: > >>> d = numpy.array(a[2],copy=False) > >>> d +=

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

2006-10-20 Thread Sebastien Bardeau
Hi! I am confused with Numpy behavior with its scalar or 0-d arrays objects: >>> numpy.__version__ '1.0rc2' >>> a = numpy.array((1,2,3)) >>> b = a[:2] >>> b += 1 >>> b array([2, 3]) >>> a array([2, 3, 3]) >>> type(b) To this point all is ok for me: subarrays share (by default) memory wit