4D np.array multiplied by a 2D np.array

52 views Asked by At

I have two numpy arrays :

  • M of shape (n_nodes, n_nodes, n_clusters, n_clusters)
  • tau of shape (n_nodes, n_clusters) I want to get the matrix K such that K[i,j,k,l] = M[i,j]**tau[j,l] I want to do it without any for loop. I tried K = M ** tau[:, np.newaxis, :, np.newaxis] but it doesn't work Anyone has an answer please ?

K = M ** tau[:, np.newaxis, :, np.newaxis]

0

There are 0 answers