# scipy - Only size-1 arrays can be converted to Python scalars: Integrate.quad Vs Integrate.quadrature

995 views

### scipy - Only size-1 arrays can be converted to Python scalars: Integrate.quad Vs Integrate.quadrature

I'm trying to calculate an integral. When I use the function scipy.integrate.quad the code works perfectly. However, when I use scipy.integrate.quadrature (I need to use this or the fixed.quad methods) it returns "only size-1 arrays can be converted to Python scalars" error. What should I do?

My code

``````import cmath as c
import math  as m
import numpy as np
import scipy as sp
import os
import csv
import time
import scipy.integrate as integrate

from scipy import special

k = 0.1

def solnum(x, chi, y):

Bk = ((2*abs(k))**(3/2))*((1+(1.5*abs(k))))*(m.gamma((1/(2*abs(k)))+(3/4))/m.gamma((1/(2*abs(k)))-(3/4)))

C = (chi/(2*m.sqrt(m.pi)))

R1 = (1/(1+(y**2)))

R2 = (((k**2)*(-((chi**2)*((x-y)**2))/4))-(m.sqrt(1+((k**2)*(-((chi**2)*((x-y)**2))/4)**2))))/(k**2 - 1)

R3 = ((((m.sqrt(1+((k**2)*(-((chi**2)*((x-y)**2))/4)**2)))) + ((k*(-((chi**2)*((x-y)**2))/4))))**(1/k))

sn = (C*Bk*R1*R2*R3)

return sn

def g(x, chi):
f1 = lambda y: solnum(x, chi, y)
return f2[0]

print(g(0.,0.05))  #for instance
``````

The error message:

``````Traceback (most recent call last):
print(g(0.,0.05))

newval = fixed_quad(vfunc, a, b, (), n)[0]

return (b-a)/2.0 * np.sum(w*func(y, *args), axis=-1), None

File "C:ProgramDataAnaconda3libsite-packagesscipyintegrate\_quadrature.py", line 149, in vfunc
return func(x, *args)

f1 = lambda y: solnum(y, x, chi)