I have a function that depends on several variables, let's say y=f(x1,x2,x3,x4)
. If each of the variables is a simple number, then the result should be a plain number. If one of the variables is an array, I need the result to be also an array. And so on: if two of the variables are arrays, I need the result to be a 2-dimensional array. Etc.
Example:
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
f(x1,x2,x3,x4)
# should give 2.0/7.0 = 0.2857...
x3=array([1.0,2.0,3.0,4.0,5.0])
f(x1,x2,x3,x4)
# should give a one-dimensional array with shape (5,)
x4=array([10.0,20.0,30.0,40.0,50.0,60.0,70.0])
f(x1,x2,x3,x4)
# should give a two-dimensional array with shape (5,7)
How to do it? (To be as clear as possible for a non-Python reader of my program?)