My code:Indexing Multi-dimensional arrays
Things become more complex when multidimensional arrays are indexed, particularly with multidimensional index arrays. These tend to be more unusual uses, but they are permitted, and they are useful for some problems. We’ll start with the simplest multidimensional case (using the array y from the previous examples):
>>> y=np.arange(35).reshape(5,7) #I added this line from previous examples.
>>>
>>> y[np.array([0,2,4]), np.array([0,1,2])]
array([ 0, 15, 30])
In this case, if the index arrays have a matching shape, and there is an index array for each dimension of the array being indexed, the resultant array has the same shape as the index arrays, and the values correspond to the index set for each position in the index arrays. In this example, the first index value is 0 for both index arrays, and thus the first value of the resultant array is y[0,0]. The next value is y[2,1], and the last is y[4,2].
Code: Select all
for i in range(manifolds):
for j in range(known):
for k in range(new):
{lots of stuff)
print "resulting 2-D array",matmul.shape,matmul.dtype
print matmul
if i==0, j==0, k==0:
correl=np.expand_dims(matmul, axis=0)
print "correl is", correl.shape, correl.dtype
correl(i,j,k)=correl.itemset(i, matmul[j,k])Code: Select all
File "nameofprog.py", line 245
correl(i,j,k)=correl.itemset(i,matmul[j,k])
SyntaxError: can't assign to function call