webknossos.geometry.vec_int
¶
Classes:
-
VecInt
–A specialized vector class for storing and manipulating integer values with named axes.
VecInt
¶
Bases: tuple
A specialized vector class for storing and manipulating integer values with named axes.
This class extends the built-in tuple type to provide vector operations while preserving axis information. It allows for initialization with both positional and named arguments.
Attributes:
-
axes
(Tuple[str, ...]
) –Names of the vector's axes, e.g. ('x', 'y', 'z')
Examples:
Create a vector with 4 named dimensions:
vector_1 = VecInt(1, 2, 3, 4, axes=("x", "y", "z", "t"))
vector_1 = VecInt([1, 2, 3, 4], axes=("x", "y", "z", "t"))
vector_1 = VecInt(x=1, y=2, z=3, t=4)
Create a vector filled with ones:
vector_2 = VecInt.full(1, axes=("x", "y", "z", "t"))
assert vector_2[0] == vector_2[1] == vector_2[2] == vector_2[3]
Perform vector addition:
assert vector_1 + vector_2 == VecInt(2, 3, 4, 5)
Methods:
-
add_or_none
–Adds two VecInts or returns None if the other is None.
-
ceildiv
–Returns a new VecInt with the ceil division of each element by the other.
-
contains
–Checks if the vector contains a given element.
-
from_str
–Returns a new ND Vector from a string representation.
-
full
–Returns a new ND Vector with all elements set to the same value.
-
is_positive
–Checks if all elements in the vector are positive.
-
is_uniform
–Checks if all elements in the vector are the same.
-
moveaxis
–Allows to move one element at index
source
to another indextarget
. Similar to -
ones
–Returns a new ND Vector with all elements set to 1.
-
pairmax
–Returns a new VecInt with the maximum of each pair of elements from the two vectors.
-
pairmin
–Returns a new VecInt with the minimum of each pair of elements from the two vectors.
-
prod
–Returns the product of all elements in the vector.
-
to_list
–Returns the vector as a list.
-
to_np
–Returns the vector as a numpy array.
-
to_tuple
–Returns the vector as a tuple.
-
with_replaced
–Returns a new ND Vector with a replaced element at a given index.
-
zeros
–Returns a new ND Vector with all elements set to 0.
Attributes:
-
axes
(Tuple[str, ...]
) – -
x
(int
) –Returns the x component of the vector.
-
y
(int
) –Returns the y component of the vector.
-
z
(int
) –Returns the z component of the vector.
add_or_none
¶
add_or_none(other: Optional[VecInt]) -> Optional[_T]
Adds two VecInts or returns None if the other is None.
Parameters:
-
other
(Optional[VecInt]
) –The other vector to add.
Returns:
-
Optional[_T]
–Optional[VecInt]: The sum of the two vectors or None if the other is None.
ceildiv
¶
ceildiv(other: Union[int, VecIntLike]) -> _T
Returns a new VecInt with the ceil division of each element by the other.
from_str
staticmethod
¶
from_str(string: str) -> VecInt
Returns a new ND Vector from a string representation.
Parameters:
-
string
(str
) –The string representation of the vector.
Returns:
-
VecInt
(VecInt
) –The new vector.
full
classmethod
¶
full(an_int: int, axes: Tuple[str, ...]) -> VecInt
Returns a new ND Vector with all elements set to the same value.
Parameters:
-
an_int
(int
) –The value to set all elements to.
-
axes
(Tuple[str, ...]
) –The axes of the vector.
Returns:
-
VecInt
(VecInt
) –The new vector.
is_positive
¶
is_positive(strictly_positive: bool = False) -> bool
Checks if all elements in the vector are positive.
Parameters:
-
strictly_positive
(bool
, default:False
) –If True, checks if all elements are strictly positive.
Returns:
-
bool
(bool
) –True if all elements are positive, False otherwise.
moveaxis
¶
moveaxis(source: Union[int, List[int]], target: Union[int, List[int]]) -> _T
Allows to move one element at index source
to another index target
. Similar to
np.moveaxis, this is not a swap operation but instead it moves the specified
source so that the other elements move when necessary.
Parameters:
-
source
(Union[int, List[int]]
) –The index of the element to move.
-
target
(Union[int, List[int]]
) –The index where the element should be moved to.
Returns:
-
VecInt
(_T
) –A new vector with the moved element.
ones
classmethod
¶
ones(axes: Tuple[str, ...]) -> VecInt
Returns a new ND Vector with all elements set to 1.
Parameters:
-
axes
(Tuple[str, ...]
) –The axes of the vector.
Returns:
-
VecInt
(VecInt
) –The new vector.
pairmax
¶
pairmax(other: Union[int, VecIntLike]) -> _T
Returns a new VecInt with the maximum of each pair of elements from the two vectors.
pairmin
¶
pairmin(other: Union[int, VecIntLike]) -> _T
Returns a new VecInt with the minimum of each pair of elements from the two vectors.
with_replaced
¶
with_replaced(index: int, new_element: int) -> _T
Returns a new ND Vector with a replaced element at a given index.
- Get Help
- Community Forums
- Email Support