等式中的参数数量无效

Ant*_*ton 2 python numpy python-2.7

y = | sin(x)| + 5*exp(-x ^ 100)*cos(x)从-3到3

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
Run Code Online (Sandbox Code Playgroud)

我想绘制这个等式,但无法编译它

Mir*_*ber 5

np.mod中,您需要指定第二个参数(除数).例如,

np.mod(np.sin(x),2)
Run Code Online (Sandbox Code Playgroud)

另外,正如@Jake Conkerton-Darby在他的文章中提到的,如果你想计算绝对值,你应该使用np.absolute而不是np.mod.


Jak*_*rby 5

该函数np.mod不是您期望的绝对值函数,而是与模运算相关,您需要提供两个值来正确计算结果.例如np.mod(5, 3) == 2,5与2模3一致.

您想要的函数调用np.absolute,它将为您提供所提供参数的绝对值.