简体   繁体   English

尽管输入了正确的数字,但 arguments 的数字无效

[英]Getting invalid number of arguments despite inputting the correct number

import numpy as np

class Body(object): # Class for planets / moons / asteroids
    
    def __init__(self, mass, velocity, position):
        
        self.mass = mass  # Defining variables
        self.velocity = velocity
        self.position = position
        
        
    def move(self, force, t):
        self.velocity = np.add(self.velocity + force * t / self.mass) # Code to move with time t
        self.position = np.add(self.position + self.velocity * t)
        return self
        
def main():
    
    mars = Body(6.4185*10**23, np.array([0, 0]), np.array([0, 0]))
    mars.move(np.array([10, 10]), 10) # Force defined to be [10, 10] and time 10
    
    
main()

Error错误

Traceback (most recent call last):
  File "c:\Users\p\Documents\dev\sodump\npadd.py", line 23, in <module>
    main()
  File "c:\Users\p\Documents\dev\sodump\npadd.py", line 20, in main
    mars.move(np.array([10, 10]), 10) # Force defined to be [10, 10] and time 10
  File "c:\Users\p\Documents\dev\sodump\npadd.py", line 13, in move
    self.velocity = np.add(self.velocity + force * t / self.mass) # Code to move with time t
ValueError: invalid number of arguments

The error is self.velocity = np.add(self.velocity + force * t / self.mass) .错误是self.velocity = np.add(self.velocity + force * t / self.mass) You pass only 1 argument while you need to pass 2 arguments.您只需传递 1 个参数,而需要传递 2 个 arguments。 Seehttps://numpy.org/doc/stable/reference/generated/numpy.add.htmlhttps://numpy.org/doc/stable/reference/generated/numpy.add.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM