The Vector Class
Vec
Bases: ndarray
A simple class to manipulate vectors in mouette. Basically, it inherits from a numpy array and implements some quality of life features for 2D and 3D vectors especially.
x: float
property
writable
First coordinate of the vector
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
|
xy
property
First two coordinates of the vector
Returns:
Name | Type | Description |
---|---|---|
float |
|
y
property
writable
Second coordinate of the vector
Returns:
Name | Type | Description |
---|---|---|
float |
|
z
property
writable
Third coordinate of the vector
Returns:
Name | Type | Description |
---|---|---|
float |
|
X()
classmethod
The [1,0,0] vector
Returns:
Name | Type | Description |
---|---|---|
Vec |
[1,0,0] |
Y()
classmethod
The [0,1,0] vector
Returns:
Name | Type | Description |
---|---|---|
Vec |
[0,1,0] |
Z()
classmethod
The [0,0,1] vector
Returns:
Name | Type | Description |
---|---|---|
Vec |
[0,0,1] |
dot(other)
Dot product between two vectors:
$ a \cdot b = \sum_i a[i]b[i]$
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
Vec
|
other vector to dot with |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the dot product |
from_complex(c)
classmethod
2D vector from complex number
Parameters:
Name | Type | Description | Default |
---|---|---|---|
c |
complex
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
Vec |
|
norm(which='l2')
Vector norm. Three norms are implemented: the Euclidean l2 norm, the l1 norm or the l-infinite norm:
l2 : $ \sqrt{ \sum_i v[i]^2 } $
l1 : $ \sum_i |v[i]| $
linf : $ \max_i |v[i]| $
Parameters:
Name | Type | Description | Default |
---|---|---|---|
which |
str
|
which norm to compute. Choices are "l2", "l1" and "linf". Defaults to "l2". |
'l2'
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the vector's norm |
normalize(which='l2')
Normalizes the vector to have unit norm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
which |
str
|
which norm to compute. Choices are "l2", "l1" and "linf". Defaults to "l2". |
'l2'
|
normalized(vec, which='l2')
staticmethod
Computes and returns a normalized vector of the input vector vec
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vec |
Vec
|
the input vector |
required |
which |
str
|
which norm to compute. Choices are "l2", "l1" and "linf". Defaults to "l2". |
'l2'
|
Returns:
Name | Type | Description |
---|---|---|
Vec |
the normalized vector |
outer(other)
Outer product between two vectors:
\(a \otimes b = c \in \mathbb{R}^{n \times n}\) such that \(c[i,j] = a[i]b[j]\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
Vec
|
the second vector |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.array: an array of shape (n,n) |
random(n)
classmethod
Generates a random vector of size n
with coefficients sampled uniformly and independently in [0;1)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
size |
required |
Returns:
Name | Type | Description |
---|---|---|
Vec |
|
zeros(n)
classmethod
Generates a vector of size n
full of zeros.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
size |
required |
Returns:
Name | Type | Description |
---|---|---|
Vec |
|