I have 2 versions of a snippet one works one doesn't, this works:
f = lambda x : x * 2.0 * pi
print(scipy.integrate.quadrature(f, 0.0, 1.0))
This fails:
f = lambda x : math.exp(x * 2.0 * pi)`
print(scipy.integrate.quadrature(f, 0.0, 1.0))
With error:
TypeError: only size-1 arrays can be converted to Python scalars
I don;t understand both are scalar functions, why is one accepted but the other is not?
You may have intended your functions to operate on scalars, but unless you pass
vec_func=False,scipy.integrate.quadraturewill assume your functions can safely take and operate elementwise over arrays.As it happens, your first
fcan indeed handle arrays, even though you didn't intend it to. Your secondfusesmath.exp, which only handles scalars.