[Numpy-discussion] Single view on multiple arrays
sturla at molden.no
Sun Nov 1 16:56:02 EST 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 = a
This would not even work, becuase a 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, as that would trigger a copy as well.
> v = b
> v = c
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.
More information about the NumPy-Discussion