I have a function that takes 2 numpy arrays as input and returns a number (real function much more complicated than the example below) :
def the_func(x,y):
return np.sum(x)*np.sum(y)
>>> the_func([2,3,4],[10,11,12])
297
So far , so good.
But then
>>> the_func([[1,2,3],[4,5,6]],[[1,2,3],[4,5,6]])
441
instead of the expected [36,225]
So I tried to vectorize
the initial function :
vfunc = np.vectorize(the_func)
But
>>> vfunc([[1,2,3],[4,5,6]],[[1,2,3],[4,5,6]])
array([[ 1, 4, 9],
[16, 25, 36]])
How can I get that function to return my result in the shape that I'd like to see (in the last example [36,225]
= [(1+2+3)*(1+2+3),(4+5+6)*(4+5+6)]
) ?