If I define a function as:
def somefunc(a, b, c):
out = [ (a+b)/c for a, b, c in zip(a, b, c) ]
return out
all the arguments must be lists of the same length, otherwise I would get the output truncated. Example: somefunc([1, 2], [3, 4], [5, 5]) would give me [0.8, 1.2].
It would be really convenient to be able to input a single number instead of a list when it doesn't change, like: somefunc([1, 2], [3, 4], 5). Of course any of the arguments can be reduced to a single value instead of a list. This can be achieved using numpy with this function definition:
from numpy import array
def somefunc(a, b, c):
a=array(a)
b=array(b)
c=array(c)
out = (a+b)/c
return out
Is there a way to do the same without numpy (and without converting all the arguments one by one)?
zipexpects iterable arguments; if your function takes non-iterable arguments, you will have to convert them.