Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用sum函数在caretsian平面上添加点_Python 3.x_Oop_Sum - Fatal编程技术网

Python 3.x 使用sum函数在caretsian平面上添加点

Python 3.x 使用sum函数在caretsian平面上添加点,python-3.x,oop,sum,Python 3.x,Oop,Sum,代码给了我一个错误。它应该在笛卡尔平面上添加点 class Cluster(object): def __init__(self, x, y): self.center = Point(x, y) self.points = [] def update(self): sum_ = sum(self.points, Point(0, 0)) len_ = float(len(self.points))

代码给了我一个错误。它应该在笛卡尔平面上添加点

class Cluster(object):
    def __init__(self, x, y):
        self.center = Point(x, y)
        self.points = []

    def update(self):
        sum_ = sum(self.points, Point(0, 0))
        len_ = float(len(self.points))
        self.center = Point(sum_.x/len_, sum_.y/len_)
        self.points = []

    def add_point(self, point):
        self.points.append(point)

 sum_ = sum(self.points, Point(0, 0))
sum()
函数仅适用于支持加法的类型。类可以使用
\uuuu add\uuu
函数实现添加。如果这确实是您面临的问题,请在
类a函数中定义如下:

类点:
# ...
定义添加(自身、其他):
返回点(self.x+other.x,self.y+other.y)