import json
import numpy as np


class NumpyEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, np.ndarray):
            return obj.tolist()
        return json.JSONEncoder.default(self, obj)


def reserialize(data: dict):
    """Converts numpy arrays into lists when serializing
    a given dictionary"""
    s = json.dumps(data, cls=NumpyEncoder)
    return json.loads(s)
