GSEGUtils.base_types
Provides predefined Numpydantic type hints to be used with Pydantic for automatic shape and dtype validation. In some cases it can also be used for type-hinting, providing easier insight into expected shape and dtype of an array.
Please read the docs for more information on usage and how you can create your own dtypes.
Use with Pydantic Models:
from pydantic import BaseModel
from numpydantic import NDArray, Shape
class ValidatedArray(BaseModel):
arr: NDArray[Shape['*, 1'], int] # This is the numpydantic component and will validate tha array
Use in instance validation:
import numpy as np
Array_Nx3_Float32_T = NDArray[Shape['*, 3'], np.float32]
isinstance(np.ones((10, 3), dtype=np.float32), Array_Nx3_Float32_T)
# True
isinstance(np.ones((10, 5), dtype=np.float32), Array_Nx3_Float32_T)
# False (incorrect shape)
isinstance(np.ones((10, 3), dtype=np.uint8), Array_Nx3_Float32_T)
# False (incorrect dtype)
Use as a callable validator:
>>> Array_Nx3_Float32_T(np.random.rand(2,3).astype(np.float32))
array([[0.9211791 , 0.89427036, 0.80592966],
[0.341839 , 0.8369464 , 0.7697314 ]], dtype=float32)
# Raises errors
>>> Array_Nx3_Float32_T(np.random.rand(2,5).astype(np.float32))
numpydantic.exceptions.ShapeError: Invalid shape! expected shape ['*', '3'], got shape (2, 5)
>>> Array_Nx3_Float32_T(np.random.randint(0, 255, (2,3), dtype=np.uint8))
numpydantic.exceptions.DtypeError: Invalid dtype! expected <class 'numpy.float32'>, got uint8
- GSEGUtils.base_types.IndexLike
Type alias for various types that can be used in numpy advanced indexing. Not a Numpydantic NDArray.
alias of
int|slice|ndarray[tuple[Any, …],dtype[bool]] |ndarray[tuple[Any, …],dtype[integer]] |Sequence
- class GSEGUtils.base_types.DtypeDict
Bases:
TypedDictDictionary object used for defining field names and types for a struct numpy array
- GSEGUtils.base_types.ArrayT
Generic
NDArraytype (supports all shapes)Additional specific dtype definitions:
Array_Float_T
Array_Integer_T
Array_SignedInteger_T
Array_UnsignedInteger_T
Array_Bool_T
Array_Float32_T
Array_Float64_T
Array_Int8_T
Array_Int16_T
Array_Int32_T
Array_Int64_T
Array_Uint8_T
Array_Uint16_T
Array_Uint32_T
- GSEGUtils.base_types.Array_NxM_T
2D Shape constrained
NDArraytype [NxM]Additional specific dtype definitions:
Array_NxM_Float_T
Array_NxM_Integer_T
Array_NxM_SignedInteger_T
Array_NxM_UnsignedInteger_T
Array_NxM_Bool_T
Array_NxM_Float32_T
Array_NxM_Float64_T
Array_NxM_Int8_T
Array_NxM_Int16_T
Array_NxM_Int32_T
Array_NxM_Int64_T
Array_NxM_Uint8_T
Array_NxM_Uint16_T
Array_NxM_Uint32_T
- GSEGUtils.base_types.Array_NxM_Float_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_Integer_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_SignedInteger_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_UnsignedInteger_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_Bool_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_Float32_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_Float64_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_Int8_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_Int16_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_Int32_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_Int64_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_Uint8_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_Uint16_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_Uint32_T
See
Array_NxM_T
- GSEGUtils.base_types.Array_NxM_3_T
3 Channel, 2D shape constrained
NDArraytype [NxMx3] E.g. RGB imagesAdditional specific dtype definitions:
Array_NxMx3_Uint8_T
- GSEGUtils.base_types.Array_NxM_3_Uint8_T
alias of
NDArray
- GSEGUtils.base_types.Array_Nx2_T
-
Array_Nx2_Float_T
Array_Nx2_Integer_T
Array_Nx2_SignedInteger_T
Array_Nx2_UnsignedInteger_T
Array_Nx2_Bool_T
Array_Nx2_Float32_T
Array_Nx2_Float64_T
Array_Nx2_Int8_T
Array_Nx2_Int16_T
Array_Nx2_Int32_T
Array_Nx2_Int64_T
Array_Nx2_Uint8_T
Array_Nx2_Uint16_T
Array_Nx2_Uint32_T
- GSEGUtils.base_types.Array_Nx2_Float_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx2_Integer_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx2_SignedInteger_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx2_UnsignedInteger_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx2_Bool_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx2_Float32_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx2_Float64_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx2_Int8_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx2_Int16_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx2_Int32_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx2_Int64_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx2_Uint8_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx2_Uint16_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx2_Uint32_T
See
Array_Nx2_T
- GSEGUtils.base_types.Array_Nx3_T
- Shape constrained [Nx3]
NDArraytypeE.g., Cartesian coordinates, normal vectors, RGB fieldsAdditional specific dtype definitions:Array_Nx3_Float_T
Array_Nx3_Integer_T
Array_Nx3_SignedInteger_T
Array_Nx3_UnsignedInteger_T
Array_Nx3_Bool_T
Array_Nx3_Float32_T
Array_Nx3_Float64_T
Array_Nx3_Int8_T
Array_Nx3_Int16_T
Array_Nx3_Int32_T
Array_Nx3_Int64_T
Array_Nx3_Uint8_T
Array_Nx3_Uint16_T
Array_Nx3_Uint32_T
- GSEGUtils.base_types.Array_Nx3_Float_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_Nx3_Integer_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_Nx3_SignedInteger_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_Nx3_UnsignedInteger_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_Nx3_Bool_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_Nx3_Float32_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_Nx3_Float64_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_Nx3_Int8_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_Nx3_Int16_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_Nx3_Int32_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_Nx3_Int64_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_Nx3_Uint8_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_Nx3_Uint16_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_Nx3_Uint32_T
See
Array_Nx3_T
- GSEGUtils.base_types.Array_3x3_T
- Shape constrained [3x3]
NDArraytypeE.g. rotation matrices and camera projection matricesAdditional specific dtype definitions:Array_3x3_Float_T
Array_3x3_Float32_T
Array_3x3_Float64_T
- GSEGUtils.base_types.Array_3x3_Float_T
See
Array_3x3_T
- GSEGUtils.base_types.Array_3x3_Float32_T
See
Array_3x3_T
- GSEGUtils.base_types.Array_3x3_Float64_T
See
Array_3x3_T
- GSEGUtils.base_types.Array_4x4_T
- Shape constrained [4x4]
NDArraytypeE.g. 3D affine transformation matrixAdditional specific dtype definitions:Array_4x4_Float_T
Array_4x4_Float32_T
Array_4x4_Float64_T
- GSEGUtils.base_types.Array_4x4_Float_T
See
Array_4x4_T
- GSEGUtils.base_types.Array_4x4_Float32_T
See
Array_4x4_T
- GSEGUtils.base_types.Array_4x4_Float64_T
See
Array_4x4_T
- GSEGUtils.base_types.VectorT
- Vector (1D
NDArray) typeE.g., scalar fields, indexes, boolean masks and segmentation classesAdditional specific dtype definitions:Vector_Float_T
Vector_Integer_T
Vector_SignedInteger_T
Vector_UnsignedInteger_T
Vector_Bool_T
Vector_Float32_T
Vector_Float64_T
Vector_Int8_T
Vector_Int16_T
Vector_Int32_T
Vector_Int64_T
Vector_Uint8_T
Vector_Uint16_T
Vector_Uint32_T
- GSEGUtils.base_types.Vector_IndexT
Special Vector type which supports integer or bool dtypes.
- GSEGUtils.base_types.Vector_3_T
- [3,] Generic 3 Element Vector typeUseful for single 3D coordinates, RGB values or other 3D VectorsAdditional specific dtype definitions:
Vector_Float_T
Vector_Integer_T
Vector_SignedInteger_T
Vector_UnsignedInteger_T
Vector_Bool_T
Vector_Float32_T
Vector_Float64_T
Vector_Int8_T
Vector_Int16_T
Vector_Int32_T
Vector_Int64_T
Vector_Uint8_T
Vector_Uint16_T
Vector_Uint32_T
- GSEGUtils.base_types.Vector_3_Float_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_3_Integer_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_3_SignedInteger_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_3_UnsignedInteger_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_3_Bool_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_3_Float32_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_3_Float64_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_3_Int8_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_3_Int16_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_3_Int32_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_3_Int64_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_3_Uint8_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_3_Uint16_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_3_Uint32_T
See
Vector_3_T
- GSEGUtils.base_types.Vector_4_T
Vector of size 4
- GSEGUtils.base_types.Vector_2_T
Vector of size 2
- GSEGUtils.base_types.make_ndarray_type(*dimensions, dtype=None)
Makes a
NDArrayType object from a defined shape and dtype- Parameters:
dtype (
npt.DTypeLike| None)
- Return type:
Examples
>>> make_ndarray_type(3, 4, dtype=np.float32) # => NDArray[Shape['3, 4'], dtype=np.float32]] >>> make_ndarray_type(3, None, None, None, dtype=np.uint8) # => NDArray[Shape['3, *, *, *'], dtype=np.uint8]]