[Matrix-SIG] QUERY: Array indexing
Janne Sinkkonen
janne@avocado.pc.helsinki.fi
10 Mar 1999 22:19:08 +0200
Stuart Feerick <smf26@cus.cam.ac.uk> writes:
> I have an index of values, i=[1,2,3], and need to access element
> [1,2,3] of the array, a=array([3,3,3]). How do I do this going through i?
As far as I understand what you want, you can just write a[i]=5, for
example, or z=a[i]. the variable i may be a sequence of indexes:
a=zeros((2,3,4))
for i in transpose(reshape(indices(a.shape),(len(a.shape),-1))): a[i]=1
There's also the operator module which may allow more flexibility:
import operator
value1=operator.__getitem__(a,i)
operator.__setitem__(a,i,value2)
--
Janne