x = np.linspace(-3,3)
y = np.mod(np.sin(x)) + 5*np.exp(-x**100)*np.cos(x) #from -3 to 3
ValueError: invalid number of arguments
我想绘制这个等式,但无法编译它
答案 0 :(得分:5)
在np.mod中,您需要指定第二个参数(除数)。例如,
np.mod(np.sin(x),2)
另外,正如@Jake Conkerton-Darby在他的文章中提到的,如果你想计算绝对值,你应该使用np.absolute而不是np.mod。
答案 1 :(得分:5)
The function np.mod
is not the absolute value function that you are expecting it to be, but is instead related to modular arithmetic中使用,您需要提供两个值才能正确计算结果。例如np.mod(5, 3) == 2
为5是一致2模3。
您想要的函数调用是np.absolute
,它将为您提供所提供参数的绝对值。