I have a matrix x
(dim = (2, 3) for instance) and I would like to calculate the outer product of each row of the matrix with itself, obtaining a tensor with the shape (2, 3, 3).
In python I can do this using numpy.einsum
import numpy as np
x = np.array([[1, 2, 3], [4, 5, 6]])
np.einsum('...j,...l', x, x)
#array([[[ 1, 2, 3],
# [ 2, 4, 6],
# [ 3, 6, 9]],
#
# [[16, 20, 24],
# [20, 25, 30],
# [24, 30, 36]]])
Would it be possible to do the same in Scala using Breeze?