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.
- class NumpyInterface(shape: Tuple[int, ...] | Any = typing.Any, dtype: str | type | Any | generic = typing.Any)[source]¶
Numpy
ndarrays!- 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 to_json(array: ndarray, info: SerializationInfo = None) list | JsonDict[source]¶
Convert an array of
return_typeto a JSON-compatible format using base python types