copapy.vector#

class copapy.vector(values)#

Bases: ArrayType[TNum]

Mathematical vector class supporting basic operations and interactions with values.

values#

The elements of the vector.

Type:

tuple[value[TNum] | TNum, …]

ndim#

Number of dimensions (always 1 for vector).

Type:

int

shape#

Shape of the vector as a tuple.

Type:

tuple[int, …]

Create a vector with given values.

Parameters:

values (Iterable[TypeVar(TNum, int, float) | value[TypeVar(TNum, int, float)]]) – iterable of constant values

cross(other)#

Calculate the cross product of this vector with another 3D vector.

Parameters:

other (vector[float]) – Another 3D vector.

Return type:

vector[float]

Returns:

A new vector perpendicular to both vectors.

dot(other)#
Overloads:
  • self (vector[int]), other (vector[int]) → int | value[int]

  • self, other (vector[float]) → float | value[float]

  • self (vector[float]), other (vector[int] | vector[float]) → float | value[float]

  • self, other (vector[int] | vector[float]) → float | int | value[float] | value[int]

Calculate the dot product of this vector with another.

Parameters:

other (vector[int] | vector[float]) – Another vector of the same length.

Returns:

The dot product as a scalar value.

get_scalar(index)#

Get a single scalar value from the vector.

Parameters:

index (int) – The index of the element to retrieve.

Return type:

TypeVar(TNum, int, float) | value[TypeVar(TNum, int, float)]

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[TypeVar(TNum, int, float)]

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.

Parameters:

func (Callable[[Any], value[TypeVar(U, int, float)] | TypeVar(U, int, float)]) – A function that takes a single argument.

Return type:

vector[TypeVar(U, int, float)]

Returns:

A new vector with the function applied to each element.

normalize()#

Calculate a normalized (unit length) version of the vector.

Return type:

vector[float]

Returns:

A normalized (unit length) vector.

sum()#
Overloads:
  • self (vector[int]) → int | value[int]

  • self (vector[float]) → float | value[float]

Sum of all vector elements.

Returns:

The sum of all vector elements as a scalar value.