title: TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'
body: <p>I need to make an integral of the type g(u)jn(u) where g(u) is a smooth function without zeros and jn(u) in the Bessel function with infinity zeros, but I got the following error:</p>
  
  <pre><code>TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'
  </code></pre>
  
  <p>First I need to change of variable x to variable u and make an integration in the new variable u but how the function u(x) is not analytically invertible so I need to use interpolation to make this inversion numerically.</p>
  
  <pre><code>import numpy as np
  from scipy.interpolate import InterpolatedUnivariateSpline
  
  x = np.linspace(0.1, 100, 1000)
  u = lambda x: x*np.exp(x)
  dxdu_x = lambda x: 1/((1+x) * np.exp(x))               ## dxdu as function of x: not invertible
  dxdu_u = InterpolatedUnivariateSpline(u(x), dxdu_x(x)) ## dxdu as function of u: change of variable
  </code></pre>
  
  <p>After this, the integral is:</p>
  
  <pre><code>from mpmath import mp
  
  def f(n):
      integrand = lambda U: dxdu_u(U) * mp.besselj(n,U)
      bjz = lambda nth: mp.besseljzero(n, nth)
      return mp.quadosc(integrand, [0,mp.inf], zeros=bjz)
  </code></pre>
  
  <p>I use <code>quadosc</code> from <code>mpmath</code> and not <code>quad</code> from <code>scipy</code> because <code>quadosc</code> is more appropriate to make integral of rapidly oscillating functions, like Bessel functions. But, by other hand, this force me to use two different packges, <code>scipy</code> to calculate <code>dxdu_u</code> by interpolation, and <code>mpmath</code> to calculate the Bessel functions <code>mp.besselj(n,U)</code> and the integral of the product <code>dxdu_u(U) * mp.bessel(n,U)</code> so I suspect that this mix of two different packages can make some issue/ conflict. So when I make:</p>
  
  <pre><code>print(f(0))
  </code></pre>
  
  <p>I got the error:</p>
  
  <pre><code>---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-38-ac2976a6b736&gt; in &lt;module&gt;
       12     return mp.quadosc(integrand, [0,mp.inf], zeros=bjz)
       13 
  ---&gt; 14 f(0)
  
  &lt;ipython-input-38-ac2976a6b736&gt; in f(n)
       10     integrand = lambda U: dxdu_u(U) * mp.besselj(n,U)
       11     bjz = lambda nth: mp.besseljzero(n, nth)
  ---&gt; 12     return mp.quadosc(integrand, [0,mp.inf], zeros=bjz)
       13 
       14 f(0)
  
  TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'
  </code></pre>
  
  <p>Does anyone know how I can solve this problem?
  Thanks</p>