using SciPy to integrate a function that returns a matrix or array

后端 未结 5 1545
野趣味
野趣味 2020-12-16 15:07

I have a symbolic array that can be expressed as:

from sympy import lambdify, Matrix

g_sympy = Matrix([[   x,  2*x,  3*x,  4*x,  5*x,  6*x,  7*x,  8*x,   9*         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 16:06

    The first argument to either quad or quadrature must be a callable. The vec_func argument of the quadrature refers to whether the argument of this callable is a (possibly multidimensional) vector. Technically, you can vectorize the quad itself:

    >>> from math import sin, cos, pi
    >>> from scipy.integrate import quad
    >>> from numpy import vectorize
    >>> a = [sin, cos]
    >>> vectorize(quad)(a, 0, pi)
    (array([  2.00000000e+00,   4.92255263e-17]), array([  2.22044605e-14,   2.21022394e-14]))
    

    But that's just equivalent to explicit looping over the elements of a. Specifically, it'll not give you any performance gains, if that's what you're after. So, all in all, the question is why and what exactly you are trying to achieve here.

提交回复
热议问题