pixano_inference.pydantic.nd_array
Pydantic models for N-dimensional arrays.
NDArray
Bases: BaseModel
, Generic[T]
, ABC
Represents an N-dimensional array.
Attributes:
Name | Type | Description |
---|---|---|
values |
list[T]
|
The list of values. |
shape |
list[int]
|
The shape of the array, represented as a list of integers. |
np_dtype |
dtype
|
The NumPy data type of the array. |
from_numpy(arr)
classmethod
Create an instance of the class from a NumPy array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr
|
ndarray
|
The NumPy array to convert. |
required |
Returns:
Type | Description |
---|---|
Self
|
An instance of the class with values and shape derived from the input array. |
Source code in pixano_inference/pydantic/nd_array.py
from_torch(tensor)
classmethod
Create an instance of the class from a PyTorch tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor
|
Tensor
|
The PyTorch tensor to convert. |
required |
Returns:
Type | Description |
---|---|
Self
|
An instance of the class with values and shape derived from the input tensor. |
Source code in pixano_inference/pydantic/nd_array.py
to_numpy()
Convert the instance to a NumPy array.
Returns:
Type | Description |
---|---|
ndarray
|
A NumPy array with values and shape derived from the instance. |
Source code in pixano_inference/pydantic/nd_array.py
to_torch()
Convert the instance to a PyTorch tensor.
Returns:
Type | Description |
---|---|
Tensor
|
A PyTorch tensor with values and shape derived from the instance. |