Numpy

Interface to numpy arrays

pydantic model NumpyJsonDict[source]

JSON-able roundtrip representation of numpy array

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Fields:
field dtype: str [Required]
field shape: tuple[int, ...] | None = None
field type: Literal['numpy'] [Required]
field value: list [Required]
to_array_input() ndarray[source]

Construct a numpy array

class NumpyInterface(shape: tuple[int, ...] | Any = typing.Any, dtype: str | type | Any | generic = typing.Any)[source]

Numpy ndarray s!

return_type

alias of ndarray

json_model

alias of NumpyJsonDict

priority: int = -999

The numpy interface is usually the interface of last resort. We want to use any more specific interface that we might have, because the numpy interface checks for anything that could be coerced to a numpy array (see NumpyInterface.check() )

classmethod check(array: Any) bool[source]

Check that this is in fact a numpy ndarray or something that can be coerced to one

before_validation(array: Any) ndarray[source]

Coerce to an ndarray. We have already checked if coercion is possible in check()

classmethod enabled() bool[source]

Check that numpy is present in the environment

classmethod to_json(array: ndarray, info: SerializationInfo = None) list | JsonDict[source]

Convert an array of return_type to a JSON-compatible format using base python types