HashableArrayContainer
- class ssapy.compute.HashableArrayContainer(arr)[source][source]
Bases:
object
A container for NumPy arrays that makes them hashable and immutable.
This class wraps a NumPy array and ensures that it is immutable by setting its writeable flag to False. It also provides implementations for __hash__ and __eq__, enabling the wrapped array to be used as a key in hash-based data structures like dictionaries and sets.
- __eq__(rhs)[source][source]
Compares the wrapped array with another HashableArrayContainer instance for equality based on element-wise comparison.
Examples
>>> import numpy as np >>> arr1 = np.array([1, 2, 3]) >>> arr2 = np.array([1, 2, 3]) >>> container1 = HashableArrayContainer(arr1) >>> container2 = HashableArrayContainer(arr2) >>> container1 == container2 True >>> hash(container1) == hash(container2) True >>> my_dict = {container1: "value"} >>> my_dict[container2] 'value'