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 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
¶
ceildiv
¶
ceildiv(other: Union[int, VecIntLike]) -> _T
Returns a new VecInt with the ceil division of each element by the other.
from_str
staticmethod
¶
full
classmethod
¶
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
¶
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
¶
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