I'm trying to write the following expression using the einsum function in NumPy:
for j in range(100):
p[j] = 0
for i in range(100):
if i!=j:
p[j] += S[i,j]*B[T[i,j], i]
p.shape = (1,100)
S.shape = (100,100)
B.shape = (N,100)
T.shape = (100,100)
N is chosen such that it exceeds the maximum value in the matrix T.
Is this possible to implement using the einsum function? If not, is there another way to optimise this?
I've searched the documentation, and it looks like it'll need some kind of broadcasting operation before being inserted into the einsum expression. But I can't get the expression right.