MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / norm_squared

Function norm_squared

machine_learning/support_vector_machines.py:6–24  ·  view source on GitHub ↗

Return the squared second norm of vector norm_squared(v) = sum(x * x for x in v) Args: vector (ndarray): input vector Returns: float: squared second norm of vector >>> int(norm_squared([1, 2])) 5 >>> int(norm_squared(np.asarray([1, 2]))) 5 >>>

(vector: ndarray)

Source from the content-addressed store, hash-verified

4
5
6def norm_squared(vector: ndarray) -> float:
7 """
8 Return the squared second norm of vector
9 norm_squared(v) = sum(x * x for x in v)
10
11 Args:
12 vector (ndarray): input vector
13
14 Returns:
15 float: squared second norm of vector
16
17 >>> int(norm_squared([1, 2]))
18 5
19 >>> int(norm_squared(np.asarray([1, 2])))
20 5
21 >>> int(norm_squared([0, 0]))
22 0
23 """
24 return np.dot(vector, vector)
25
26
27class SVC:

Callers 1

__rbfMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected