-1

I'm having a similar issue as to this post:

Why does this simple numpy multiply operation raise an "invalid number of arguments" error?

I have this incredibly confusing equation in my code:

(m[0]*np.power(q[0])*q[0]*r[0]*(m[0]*R)*np.power(q[0]))/(R*((m[0]*R)*np.power(q[0])+m*np.power(q[0]))**2) - a[0]*N/(b[0]+N)

and when I run it, it returns the error:

ValueError: invalid number of arguments

I assumed it could have something to do with the ** I was using to define the exponents (q[0] is an exponent), so I substituted those to np.power() to no success. Also, I changed the / that I am using to define the fractions to *(.....)**(-1), but that didn't work either. At this point, I'm assuming the issue is with the * I'm using for multiplications. But how can I write multiplications and divisions in this long expression without raising a position error?

Thank you in advance for the help!

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    Please provide an MCVE and a stack trace. The error will tell you where it happened. You can run a debugger to figure out the problem. – Mad Physicist Oct 13 '20 at 02:02
  • You could try breaking the calculation into smaller chunks to figure out exactly which part of your equation causes the problem. Otherwise, you will need to provide a [mcve], because we have no way of knowing what is in your variables. – Craig Oct 13 '20 at 02:03
  • "I have this incredibly confusing equation in my code:" Well, did you try *not* having it? Break it down into smaller pieces until you find the piece that causes the problem. – Karl Knechtel Oct 13 '20 at 02:09
  • 1
    "I assumed it could have something to do with the \*\* I was using to define the exponents (q[0] is an exponent), so I substituted those to np.power() to no success" I don't understand. What is the intended base for the exponentiation? What is the intended exponent for the exponentiation? When you try to write this part **by itself**, what did it look like using `**`, and what *exactly* does it tell you is wrong? How about using `np.power`? – Karl Knechtel Oct 13 '20 at 02:11
  • 1
    The discussion in your link about `*` and `/` is about notation in the function signature documentation. It has nothing to do with `**`, `*` or `/` used as operators in your expression. `np.power` makes it clear that it expects **2** arguments. The other arguments are keyword ones that you don't need to use. – hpaulj Oct 13 '20 at 02:31
  • 1
    In case it isn't clear from other comments and the answer, `np.power(x, y)` and `x**y` are equivalent expressions. – hpaulj Oct 13 '20 at 02:33
  • 1
    I've rolled back your edit adding an answer in your question. I'm glad you found a solution to your problem. However, an actual answer/solution should **not** be edited into your Question. In general, you should [edit] the Question to *clarify the Question*, but not to include an Answer within the Question. You should create your own Answer with the code you used to solve your problem, then accept it (the system may require a 48-hour delay prior to accepting your own answer). – Dharman Oct 24 '20 at 23:28

1 Answers1

1

You have to add another argument of what power you want.
For example, power means add 2 For example, cube means add 3

np.power(x1, 2)
np.power(x1, 3)

If you just want to squre with np.power(), then I have already edited the code for you:

(m[0]*np.power(q[0], 2)*q[0]*r[0]*(m[0]*R)*np.power(q[0], 2))/(R*((m[0]*R)*np.power(q[0], 2)+m*np.power(q[0], 2))**2) - a[0]*N/(b[0]+N)
Kiwirafe
  • 574
  • 4
  • 12