Spyridoula Georgiou
Spyridoula Georgiou

Reputation: 3

How to fix type 'int' has no len()?

I can't understand what's wrong with this code. Can someone help me please? This is a Pareto type II integrand from 1 to infinite and a and b are the parameters of the distribution. TypeError: object of type 'int' has no len() -> that's the error when I try to compute E

import numpy as np
from scipy.integrate import quad
from mpmath import *

def integrand(a, b, x):
    return x*a(b**a)/((x+1)**a)

a = 3                                                                                     
b = 2

E = quad(integrand, 1, np.inf, args=(a, b))
E

Upvotes: 0

Views: 2208

Answers (2)

yanas rajindran
yanas rajindran

Reputation: 46

This looks like import error to me ,both scipy and mpmath have implementation for quad method so to make the code work,will have to remove mpmath import statement. I could run the code as below..getting overflow for large value of the upper limit

import numpy as np
from scipy import integrate
#from scipy.integrate import quad
from mpmath import *

def intergrand(a, b, x):
    return x*a*(b**a)/((x+b)**a)
a = 3                                                                                     
b = 2

E = integrate.quad(intergrand,1, 100, args=(a, b))
print(E)

Upvotes: 3

Warren Weckesser
Warren Weckesser

Reputation: 114811

Remove the line

from mpmath import *

from your code.

mpmath has a quad function, so when you do from mpmath import *, you are overwriting the name that you imported from SciPy. You got the error TypeError: object of type 'int' has no len() because mpmath's version of quad expects the second argument to have the form [a, b], but you passed in 1.

Upvotes: 2

Related Questions