Invalid number of arguments in equation

10,471

Solution 1

The function np.mod is not the absolute value function that you are expecting it to be, but is instead related to modular arithmetic, and you need to provide it two values to correctly calculate the result. For example np.mod(5, 3) == 2 as 5 is congruent to 2 modulo 3.

The function call you are wanting is np.absolute, which whill give you the absolute value of the provided argument.

Solution 2

In np.mod you need to specify the second argument (the divisor). For example,

np.mod(np.sin(x),2)

In addition, as @Jake Conkerton-Darby mentioned in his anwers, if you want to calculate absolute value you should use np.absolute and not np.mod.

Share:
10,471
Anton
Author by

Anton

Updated on June 15, 2022

Comments

  • Anton
    Anton almost 2 years

    y = |sin(x)| + 5*exp(-x^100)*cos(x) from -3 to 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
    

    i want to plot this equation but can't compile it

    • MSeifert
      MSeifert almost 7 years
      Note that np.exp(-x**100) will be subject to over and underflow. The result might not be nearly as accurate as you want or need it to be.