MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / __add__

Method __add__

linear_algebra/src/lib.py:72–83  ·  view source on GitHub ↗

input: other vector assumes: other vector has the same size returns a new vector that represents the sum.

(self, other: Vector)

Source from the content-addressed store, hash-verified

70 return "(" + ",".join(map(str, self.__components)) + ")"
71
72 def __add__(self, other: Vector) -> Vector:
73 """
74 input: other vector
75 assumes: other vector has the same size
76 returns a new vector that represents the sum.
77 """
78 size = len(self)
79 if size == len(other):
80 result = [self.__components[i] + other.component(i) for i in range(size)]
81 return Vector(result)
82 else:
83 raise Exception("must have the same size")
84
85 def __sub__(self, other: Vector) -> Vector:
86 """

Callers

nothing calls this directly

Calls 2

VectorClass · 0.85
componentMethod · 0.45

Tested by

no test coverage detected