Numpy vector/matrix multiplication works unexpectedly

Viewed 89

I have a problem with my code: I want to multiply two "vectors" in the way seen below

# what i want
import numpy as np

a = np.array([1,2,3])
b = np.array([2,3,4,5])
z = f(a,b)

z -> array([
    [2,3,4,5],
    [4,6,8,10],
    [6,9,12,15]
])

How should f be defined?

2 Answers

You can use np.matmul function on reshaped arrays like

a = np.reshape(a, (3,1))
b = np.reshape(b, (1,4))
np.matmul(a,b)
Related