nip.utils.nested_array_dict.CompositeSpec#
- class nip.utils.nested_array_dict.CompositeSpec(shape: tuple[int], dim_names: tuple[str] | str | None = None, **specs: dict[str, NumpySpec])[source]#
Specification for a nested dictionary of numpy arrays.
Methods Summary
__eq__
(other)Return self==value.
__getitem__
(key)__init__
(shape[, dim_names])__repr__
()Return repr(self).
__setitem__
(key, value)keys
([recurse])Iterate over the keys of CompositeSpec, optionally recursing to sub-specs.
zero
()Return a dictionary of zero arrays with the specified shape.
Attributes
dim_names
shape
Methods
- __eq__(other)#
Return self==value.
- __init__(shape: tuple[int], dim_names: tuple[str] | str | None = None, **specs: dict[str, NumpySpec])[source]#
- __repr__()#
Return repr(self).
- keys(recurse=False)[source]#
Iterate over the keys of CompositeSpec, optionally recursing to sub-specs.
- Parameters:
recurse (bool, default=False) – Whether to recurse to sub-specs. In this case, the keys are tuples of strings representing the path to the data in the nested dictionary.
- Yields:
key (str | tuple[str, …]) – The key of the spec. If recurse is True, the key is a tuple of strings representing the path to the data in the nested dictionary. Otherwise, the key is a string.
- zero() NestedArrayDict [source]#
Return a dictionary of zero arrays with the specified shape.
- Returns:
zero_dict (NestedArrayDict) – The dictionary of zero arrays with the specified shape.