hash_numpy_array

function of dascore.utils.array source

hash_numpy_array(
    arr: ndarray ,
)-> ‘str’

Return a stable hash for a NumPy array.

Fast path: - zero-copy for C-contiguous arrays Fallback: - makes one contiguous copy for non-contiguous arrays

The hash includes: - dtype - shape - raw array bytes

Returns

str 32-character hex string (16-byte BLAKE2b digest).

Examples

import numpy as np
from dascore.utils.array import hash_numpy_array
a = np.array([1.0, 2.0, 3.0])
h = hash_numpy_array(a)
assert isinstance(h, str) and len(h) == 32
# Same data always produces the same hash
assert hash_numpy_array(a) == hash_numpy_array(a.copy())
# Different dtype produces a different hash
assert hash_numpy_array(a) != hash_numpy_array(a.astype(np.float32))