I need to integrate a matrix function as in the example below:
def func(a1, a2, a3):
return np.array([a1, (a1 + a2), a3])
The non-efficient way to do this is using three for loops. Although, I would like to make it more efficient. I thought about using "map", like:
def integral(func, a1, a2, a3, w):
f = np.array(list(map(func, a1, a2, a3)))
I = np.zeros((3, ))
for fi, wi in zip(f, w):
I = I + wi*np.array(fi)
return I
a1
, a2
, a3
and w
are arrays of the same size (a's are the sample points and w are the weights)
Is this the most optimized way to do so?