swarmsim.yaml.np_representer#
Provides a slightly more human-readable YAML representer for numpy arrays.
- swarmsim.yaml.np_representer.represent_ndarray(dumper: Dumper, data: ndarray)[source]#
For small arrays, return a more human-readable representation.
For large arrays, return the default representation.
- Parameters:
dumper (yaml.Dumper)
data (np.ndarray)
- Returns:
Either a YAML sequence or mapping node.
- Return type:
node
Examples#
For vectors and small matrices, we show the array as a sequence. This representation is used if:
The array is a vector with
len(array) < 11
The array is a 2D matrix with fewer than 9 elements
>>> import sys >>> import numpy as np >>> import swarmsim.yaml >>> swarmsim.yaml.dump({ 'small_array': np.array([8, 8]), 'big_array': np.ones((3, 3)), 'very_big_array': np.ones((10, 10)), }, sys.stdout)
big_array: !!python/object/apply:numpy.array args: !!python/tuple - [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]] kwargs: dtype: float64 small_array: !!python/object/apply:numpy.array args: !!python/tuple - - 8 - 8 kwargs: dtype: int64 very_big_array: !!python/object/apply:numpy._core.multiarray._reconstruct args: - !!python/name:numpy.ndarray '' - !!python/tuple - 0 - !!binary | Yg== state: !!python/tuple - 1 - !!python/tuple - 10 - 10 - !!python/object/apply:numpy.dtype args: - f8 - false - true state: !!python/tuple - 3 - < - null - null - null - -1 - 0 - false - !!binary | AAAAAAAA8D8AAAAAAADwPwAAAAAAAPA/AAAAAAAA8D8AAAAAAADwPwAAAAAAAPA/AAAAAAAA8D8A AAAAAADwPwAAAAAAAPA/AAAAAAAA8D8AAAAAAADwPwAAAAAAAPA/AAAAAAAA8D8AAAAAAADwPwAA AAAAAPA/AAAAAAAA8D8AAAAAAADwPwAAAAAAAPA/AAAAAAAA8D8AAAAAAADwPwAAAAAAAPA/AAAA AAAA8D8AAAAAAADwPwAAAAAAAPA/AAAAAAAA8D8AAAAAAADwPwAAAAAAAPA/AAAAAAAA8D8AAAAA AADwPwAAAAAAAPA/AAAAAAAA8D8AAAAAAADwPwAAAAAAAPA/AAAAAAAA8D8AAAAAAADwPwAAAAAA AP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