copapy.vector#
- class copapy.vector[TNum: (int, float)](values, packed=None)#
Bases:
ArrayType[TNum]Mathematical vector class supporting basic operations and interactions with values. A vector has one dimension: ndim is 1 and shape is (number of elements,).
Create a vector with given values.
- Parameters:
- cross(other)#
Calculate the cross product of this vector with another 3D vector.
- dot(other)#
Calculate the dot product of this vector with another.
- property dtype: str#
‘int’, ‘float’ or ‘bool’
- Type:
Type of the elements
- get_scalar(index)#
Get a single scalar value from the vector.
- Parameters:
index (
int) – The index of the element to retrieve.- Return type:
TNum|value[TNum]- Returns:
The scalar value at the specified index.
- homogenize()#
Convert all elements to Copapy values if any element is a Copapy value.
- Return type:
vector[TNum]- Returns:
Vector with homogeneous element type.
- magnitude()#
Magnitude (length) of the vector.
- Return type:
float|value[float]- Returns:
The magnitude of the vector as a scalar value.
- map(func)#
Applies a function to each element of the vector and returns a new vector.
- ndim: int#
Number of dimensions (length of shape)
- normalize()#
Calculate a normalized (unit length) version of the vector.
- Return type:
vector[float]- Returns:
A normalized (unit length) vector.
- pack_threshold: int | None = 64#
Instances are packed if more elements than pack_threshold are copapy values or constants other than zero, None disables packing and type promotion
- shape: tuple[int, ...]#
Shape of the elements, e.g. (n,) for a vector
- sum()#
Sum of all vector elements.