I have a (large) 4D array, consisting of the 5 coefficients in a given basis for a matrix field. Given the 5 basis matrices, I want to efficiently calculate the matrix field.
The coefficient field c[x,y,z,i]
being the value of i-th coefficient at position x,y,z
And the matrix field M[x,y,z,a,b]
being the (3,3)
matrix at position x,y,z
And the basis matrices T_1,...T_5
, being the (3,3)
basis matrices
I could loop over each position in space:
M[x,y,z,:,:] = T_1[:,:]*c[x,y,z,0] + T_2[:,:]*c[x,y,z,1]...T_5[:,:]*c[x,y,z,4]
But this is very inefficient. My attempts at using np.multiply
,np.sum
result in broadcasting errors due to the ambiguity of the desired product being a field of 3x3 matrices.
M[x,y,z,a,b]
and then later when you calculate itM[x,y,z]
Which one is the dimension? Can you provide a dummy example? – anishtain4np.apply_along_axis()
is a solution when supplied with a coefficient-->matrix conversion function. – Smecticeinsum
, you can packT_i
into one matrix, and then use tensor notation: docs.scipy.org/doc/numpy-1.14.0/reference/generated/… – anishtain4