Skip to content

declearn.utils.deserialize_numpy

Return a numpy array based on serialized information.

Inverse operation of declearn.utils.serialize_numpy.

Source code in declearn/utils/_numpy.py
41
42
43
44
45
46
47
48
def deserialize_numpy(data: Tuple[str, str, List[int]]) -> np.ndarray:
    """Return a numpy array based on serialized information.

    Inverse operation of `declearn.utils.serialize_numpy`.
    """
    buffer = bytes.fromhex(data[0])
    array = np.frombuffer(buffer, dtype=data[1])
    return array.reshape(data[2]).copy()  # copy makes the array writable