[Numpy-discussion] Single view on multiple arrays

Bill Blinn bblinn@gmail....
Sun Nov 1 12:50:51 CST 2009


What is the best way to create a view that is composed of sections of many
different arrays?

For example, imagine I had
a = np.array(range(0, 12)).reshape(3, 4)
b = np.array(range(12, 24)).reshape(3, 4)
c = np.array(range(24, 36)).reshape(3, 4)

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]
v[1] = b[0]
v[2] = c[0]

#change the underlying arrays
a[0, 0] = 50
b[0, 0] = 51
c[0, 0] = 52

#I would want all these assertions to pass because the view
#refers to the rows of a, b and c
assert v[0, 0] == 50
assert v[1, 0] == 51
assert v[2, 0] == 52

Is there any way to do this?

Thanks,
bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20091101/f5a6a54b/attachment.html 


More information about the NumPy-Discussion mailing list