The proper way to do this is to pass in the properly shaped data. If you want a 2d result, you should pass in 2d arrays. This can be accomplished by np.newaxis
.
import numpy as np
def f(x1,x2,x3,x4):
y = x1*x2/(x3+x4)
return y
x1 = 1.0
x2 = 2.0
x3 = 3.0
x4 = 4.0
print f(x1,x2,x3,x4)
x3 = np.array([1.0,2.0,3.0,4.0,5.0])
print f(x1,x2,x3,x4)
x3 = x3[:, np.newaxis]
x4 = np.array([10.0,20.0,30.0,40.0,50.0,60.0,70.0])
x4 = x4[np.newaxis, :]
print f(x1,x2,x3,x4)
Of course, the way your question is posed, it's a little ambiguous why you should expect to get an array shaped (5, 7)
and not an array shaped (7, 5)
.