Skip to content

webknossos.geometry.vec_int

Classes:

  • VecInt

    The VecInt class is designed to represent a vector of integers. This class is a subclass of the built-in tuple class, and it extends the functionality of tuples by providing additional methods and operations.

VecInt

Bases: tuple

The VecInt class is designed to represent a vector of integers. This class is a subclass of the built-in tuple class, and it extends the functionality of tuples by providing additional methods and operations.

One of the key features of the VecInt class is that it allows for the storage of axis names along with their corresponding values.

Here is a brief example demonstrating how to use the VecInt class:

from webknossos import VecInt

# Creating a VecInt instance with 4 elements and axes x, y, z, t:
vector_1 = VecInt(1, 2, 3, 4, axes=("x", "y", "z", "t"))
# Alternative ways to create the same VecInt instance:
vector_1 = VecInt([1, 2, 3, 4], axes=("x", "y", "z", "t"))
vector_1 = VecInt(x=1, y=2, z=3, t=4)

# Creating a VecInt instance with all elements set to 1 and axes x, y, z, t:
vector_2 = VecInt.full(1, axes=("x", "y", "z", "t"))
# Asserting that all elements in vector_2 are equal to 1:
assert vector_2[0] == vector_2[1] == vector_2[2] == vector_2[3]

# Demonstrating the addition operation between two VecInt instances:
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 index target. 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.

axes instance-attribute

axes: Tuple[str, ...]

x property

x: int

Returns the x component of the vector.

y property

y: int

Returns the y component of the vector.

z property

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.

contains

contains(needle: int) -> bool

Checks if the vector contains a given element.

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.

is_uniform

is_uniform() -> bool

Checks if all elements in the vector are the same.

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.

prod

prod() -> int

Returns the product of all elements in the vector.

to_list

to_list() -> List[int]

Returns the vector as a list.

to_np

to_np() -> ndarray

Returns the vector as a numpy array.

to_tuple

to_tuple() -> Tuple[int, ...]

Returns the vector as a tuple.

with_replaced

with_replaced(index: int, new_element: int) -> _T

Returns a new ND Vector with a replaced element at a given index.

zeros classmethod

zeros(axes: Tuple[str, ...]) -> VecInt

Returns a new ND Vector with all elements set to 0.

Parameters:

  • axes

    (Tuple[str, ...]) –

    The axes of the vector.

Returns:

  • VecInt ( VecInt ) –

    The new vector.