I want to vectorize a function f(a, b)
so that, when I enter a and b as two vectors, the tensor of combinations is returned. Here is an illustrative example:
You can chain with np.ix_
:
>>> import functools
>>>
>>> def tensorize(f):
... fv = np.vectorize(f)
... @functools.wraps(f)
... def ft(*args):
... return fv(*np.ix_(*map(np.ravel, args)))
... return ft
...
>>> tester = tensorize(tester)
>>> tester(np.arange(3), np.arange(2))
array([[0., 0.],
[0., 1.],
[0., 4.]])