# Import the NumPy library import numpy as np p, n = 10, 20 M = np.ones((p, n, n)) V = np.ones((p, n, 1)) S = np.einsum('pjk,pki->ij', M, V) print(S)