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

Method euclidean_length

linear_algebra/src/lib.py:155–173  ·  view source on GitHub ↗

returns the euclidean length of the vector >>> Vector([2, 3, 4]).euclidean_length() 5.385164807134504 >>> Vector([1]).euclidean_length() 1.0 >>> Vector([0, -1, -2, -3, 4, 5, 6]).euclidean_length() 9.539392014169456 >>> Vector([]).eucl

(self)

Source from the content-addressed store, hash-verified

153 self.__components[pos] = value
154
155 def euclidean_length(self) -> float:
156 """
157 returns the euclidean length of the vector
158
159 >>> Vector([2, 3, 4]).euclidean_length()
160 5.385164807134504
161 >>> Vector([1]).euclidean_length()
162 1.0
163 >>> Vector([0, -1, -2, -3, 4, 5, 6]).euclidean_length()
164 9.539392014169456
165 >>> Vector([]).euclidean_length()
166 Traceback (most recent call last):
167 ...
168 Exception: Vector is empty
169 """
170 if len(self.__components) == 0:
171 raise Exception("Vector is empty")
172 squares = [c**2 for c in self.__components]
173 return math.sqrt(sum(squares))
174
175 def angle(self, other: Vector, deg: bool = False) -> float:
176 """

Callers 2

angleMethod · 0.95
test_euclidean_lengthMethod · 0.95

Calls

no outgoing calls

Tested by 1

test_euclidean_lengthMethod · 0.76