From: Tim H. <tim...@ie...> - 2006-10-20 13:45:16
|
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.array(a[2],copy=False) >> >>> d += 1 >> >>> d >> >> array(4) >> >> >>> a >> >> array([2, 3, 3]) >> >> >>> type(d) >> >> <type 'numpy.ndarray'> >> >> >>> d.shape >> >> () >> >> >>> id(d) >> >> 169621280 >> >> >>> d += 1 >> >>> id(d) >> >> 169621280 >> >> This is not a solution because d is a copy since construction time... >> My question is: is there a way to get a single element of an array into >> a 0-d array which shares memory with its parent array? >> > > One possible solution (there can be more) is using ndarray: [SNIP] Here's a slightly more concise version of the same idea: b = a[n:n+1].reshape([]) -tim |