0

Suppose I have the following two arrays:

X = np.array([[1., 2., 3.],
       [1., 2., 3.],
       [1., 2., 3.],
       [1., 2., 3.]])

B = np.array([[2, 4, 6],
       [2, 4, 6],
       [2, 4, 6],
       [2, 4, 6]])

I want to compute a row wise matrix multiplication such that the output is:

y = np.array([28, 28, 28, 28]), i.e. each element in y is something like np.array([1, 2, 3]) dot np.array([2, 4, 6]) = 28

Is this possible?

fourloops
  • 9
  • 4

1 Answers1

0

You may try transposing your matrix.

X = np.array([[1., 2., 3.],
       [1., 2., 3.],
       [1., 2., 3.],
       [1., 2., 3.]])

B = np.array([[2, 4, 6],
       [2, 4, 6],
       [2, 4, 6],
       [2, 4, 6]])

y = (X @ B.T).T
samilarinc
  • 119
  • 4