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

Method __sub__

linear_algebra/src/lib.py:85–96  ·  view source on GitHub ↗

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

(self, other: Vector)

Source from the content-addressed store, hash-verified

83 raise Exception("must have the same size")
84
85 def __sub__(self, other: Vector) -> Vector:
86 """
87 input: other vector
88 assumes: other vector has the same size
89 returns a new vector that represents the difference.
90 """
91 size = len(self)
92 if size == len(other):
93 result = [self.__components[i] - other.component(i) for i in range(size)]
94 return Vector(result)
95 else: # error case
96 raise Exception("must have the same size")
97
98 def __eq__(self, other: object) -> bool:
99 """

Callers

nothing calls this directly

Calls 2

VectorClass · 0.85
componentMethod · 0.45

Tested by

no test coverage detected