def foo(A, U, V):
    A3 = A.copy()
U1 = U[(A.row), :]
V1 = V[:, (A.col)]
A3.data[:] = np.einsum('ij,ji->i', U1, V1)
return A3
A3 = foo(A, U, V)
print(np.allclose(A1, A3.A))
Python - matrix multiplication with sparse result