'I am attempting to integrate a sine wave. I am getting a valueError: invalid callable given

import numpy as np
import scipy.integrate as integrate


time = np.arange(0.0, 1, 0.0001)
test = np.sin(time)

test2 = integrate.quad(test,0,0.01)

I set up time with np.arange I then create the sin function I then attempt to integrate the function

Traceback:
Traceback (most recent call last):
  File "/home/andrew/PycharmProjects/memresistor/test.py", line 8, in <module>
    test = integrate.quad(test,0,0.01)
  File "/home/andrew/PycharmProjects/memresistor/venv/lib/python3.8/site-packages/scipy/integrate/_quadpack_py.py", line 351, in quad
    retval = _quad(func, a, b, args, full_output, epsabs, epsrel, limit,
  File "/home/andrew/PycharmProjects/memresistor/venv/lib/python3.8/site-packages/scipy/integrate/_quadpack_py.py", line 463, in _quad
    return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
ValueError: invalid callable given


Solution 1:[1]

I think this is the misunderstanding: np.sin is a function. np.sin() is not. When the () is added to the end, the function is called and will be evaluated, thus no longer being a function. Does this work for you?

import numpy as np
import scipy.integrate as integrate

test = integrate.quad(np.sin, 0, 1)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cresht