Vector Operations
The vector library provides operations on vectors represented as Python lists of Real numbers.
Construction
- fpy2.libraries.vector.zeros(n)
Create a zero vector of length n.
- Parameters:
n (int) – Vector length
- Returns:
Zero vector
- Return type:
list[Real]
- fpy2.libraries.vector.ones(n)
Create a vector of ones of length n.
- Parameters:
n (int) – Vector length
- Returns:
Vector of ones
- Return type:
list[Real]
Element-wise Operations
- fpy2.libraries.vector.add(x, y)
Element-wise addition of two vectors.
- Parameters:
x (list[Real]) – First vector
y (list[Real]) – Second vector
- Returns:
Result vector x + y
- Return type:
list[Real]
- fpy2.libraries.vector.sub(x, y)
Element-wise subtraction of two vectors.
- Parameters:
x (list[Real]) – First vector
y (list[Real]) – Second vector
- Returns:
Result vector x - y
- Return type:
list[Real]
- fpy2.libraries.vector.hadamard(x, y)
Element-wise multiplication (Hadamard product) of two vectors.
- Parameters:
x (list[Real]) – First vector
y (list[Real]) – Second vector
- Returns:
Result vector x ⊙ y
- Return type:
list[Real]
- fpy2.libraries.vector.scale(a, x)
Scale a vector by a scalar.
- Parameters:
a (Real) – Scalar multiplier
x (list[Real]) – Input vector
- Returns:
Result vector a*x
- Return type:
list[Real]
Products
- fpy2.libraries.vector.dot(x, y)
Compute the dot product of two vectors.
- Parameters:
x (list[Real]) – First vector
y (list[Real]) – Second vector
- Returns:
Dot product of x and y
- Return type:
Real
- fpy2.libraries.vector.dot_add(x, y, c)
Compute xy + c, dot product with addition.
- Parameters:
x (list[Real]) – First vector
y (list[Real]) – Second vector
c (Real) – Scalar to add
- Returns:
Result x·y + c
- Return type:
Real
- fpy2.libraries.vector.cross(x, y)
Compute cross product of two 3D vectors.
- Parameters:
x (list[Real]) – First 3D vector
y (list[Real]) – Second 3D vector
- Returns:
Cross product x × y
- Return type:
list[Real]
BLAS-like Operations
- fpy2.libraries.vector.axpy(a, x, y)
Compute a*x + y (AXPY operation).
- Parameters:
a (Real) – Scalar multiplier
x (list[Real]) – First vector
y (list[Real]) – Second vector
- Returns:
Result vector a*x + y
- Return type:
list[Real]
Norms
- fpy2.libraries.vector.norm1(x)
Compute the L1 norm (Manhattan norm) of a vector.
- Parameters:
x (list[Real]) – Input vector
- Returns:
L1 norm of x
- Return type:
Real
- fpy2.libraries.vector.norm2(x)
Compute the L2 norm (Euclidean norm) of a vector.
- Parameters:
x (list[Real]) – Input vector
- Returns:
L2 norm of x
- Return type:
Real
- fpy2.libraries.vector.norm_inf(x)
Compute the infinity norm (maximum norm) of a vector.
- Parameters:
x (list[Real]) – Input vector
- Returns:
Infinity norm of x
- Return type:
Real
- fpy2.libraries.vector.norm_p(x, p)
Compute the p-norm of a vector.
- Parameters:
x (list[Real]) – Input vector
p (Real) – Norm parameter (p >= 1)
- Returns:
p-norm of x
- Return type:
Real
Normalization
- fpy2.libraries.vector.normalize(x)
Normalize a vector to unit length (L2 norm).
- Parameters:
x (list[Real]) – Input vector
- Returns:
Unit vector in direction of x
- Return type:
list[Real]
- fpy2.libraries.vector.normalize_p(x, p)
Normalize a vector using p-norm.
- Parameters:
x (list[Real]) – Input vector
p (Real) – Norm parameter
- Returns:
Vector normalized by p-norm
- Return type:
list[Real]
Similarity and Distance
- fpy2.libraries.vector.cosine_similarity(x, y)
Compute cosine similarity between two vectors.
- Parameters:
x (list[Real]) – First vector
y (list[Real]) – Second vector
- Returns:
Cosine similarity x·y / (||x|| ||y||)
- Return type:
Real
Statistics
- fpy2.libraries.vector.mean(x)
Compute the mean of vector elements.
- Parameters:
x (list[Real]) – Input vector
- Returns:
Mean of elements
- Return type:
Real
- fpy2.libraries.vector.min_element(x)
Find minimum element in vector.
- Parameters:
x (list[Real]) – Input vector
- Returns:
Minimum element
- Return type:
Real
- fpy2.libraries.vector.max_element(x)
Find maximum element in vector.
- Parameters:
x (list[Real]) – Input vector
- Returns:
Maximum element
- Return type:
Real