title: Python. Problems with integrals. TypeError: only size-1 arrays can be converted to Python scalars
body: <p>I am trying to find an array of integrate function but i have some problem with shapes and dimensions. I found coefficient k and then i found Energy for the interval x = (0,a), where a = 1 and n = (-Nmax, Nmax). I was also trying to vectorize them. But every time it gives me new errors. I'm not sure how to fix this, because i need this integrate function to call to another function to plot the graph.</p>
  
  <pre><code>def k_n(n):
      k = fsolve(lambda n : np.tan(n*a/2.) - np.tanh(n*a/2.),n)
      return(k)
  
  def E(n):
      return(np.piecewise(n,[n&lt;0.,n&gt;=0.],
                          [lambda n: -k_n(n)**2 ,
                           lambda n: k_n(n)**2 ]))
  
  def integrand1(x,n):
      return(np.sin(k_n(n)*x)**2)
  
  def integrand2(x,n):
      return((np.sin(k_n(n)*a/2.))**2*(np.sinh(k_n(n)*(a-x)))**2/2*
  np.exp(-a*k_n(n))*(np.sinh(k_n(n)*a/2.))**2)
  
  def integrate(n): 
      integrand = spi.integrate.quad(integrand1,0,a/2,args=(n))+spi.integrate.quad(integrand2,a/2,a,args=(n)) 
      one = np.true_divide(1, integrand )
      return(one)
  </code></pre>
  
  <p>maybe the problem is with <code>n_r</code> and <code>x_r</code></p>
  
  <pre><code>n_r = np.arange(-Nmax, Nmax,1)
  x_r = np.arange(0,a,.1)
  
  print(k_n(n_r))
  print(E(n_r))
  print(integrate(n_r))`
  </code></pre>
  
  <blockquote>
    <p>TypeError: only size-1 arrays can be converted to Python scalars.in _quad
        return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit</p>
  </blockquote>