Cache decorator for numpy arrays
问题 I am trying to make a cache decorator for functions with numpy array input parameters from functools import lru_cache import numpy as np from time import sleep a = np.array([1,2,3,4]) @lru_cache() def square(array): sleep(1) return array * array square(a) But numpy arrays are not hashable, TypeError Traceback (most recent call last) <ipython-input-13-559f69d0dec3> in <module>() ----> 1 square(a) TypeError: unhashable type: 'numpy.ndarray' So they need to be converted to tuples. I have this