This is my python code And am getting this error: Why is that so? Integration using quad method worked fine but not with trapz method Answer As a user commented, you can only use math functions with scalar values, for arrays you have to use math functions provided in NumPy library.