[Numpy-discussion] Single view on multiple arrays
Sturla Molden
sturla@molden...
Sun Nov 1 15:56:02 CST 2009
Bill Blinn skrev:
> v = multiview((3, 4))
> #the idea of the following lines is that the 0th row of v is
> #a view on the first row of a. the same would hold true for
> #the 1st and 2nd row of v and the 0th rows of b and c, respectively
> v[0] = a[0]
This would not even work, becuase a[0] does not return a view array but
a scalar arrays, which is a different type of numpy objects. To get a
view, you will need to:
v = a[0:1] # view of element 0 in a
Also you cannot assign to v[0], as that would trigger a copy as well.
> v[1] = b[0]
> v[2] = c[0]
As I mentioned in the answer to Anne, it would take a completely
different array object. It would need to internally store an array with
memory addresses. I have not made up my mind if ndarray can be
subclassed for this, or if it takes a completely different object (e.g.
similar to numpy.memmap). What it would require is __setitem__ to store
pointers and __getitem__ to dereference (return an ndarray with values).
Good look hacking, it is not even difficult, just tedious.
Sturla
More information about the NumPy-Discussion
mailing list