hashable_ndarray module¶
A hashable NumPy array.
- class gemseo.algos.hashable_ndarray.HashableNdarray(array, copy=False)[source]¶
Bases:
object
HashableNdarray wrapper for ndarray objects.
Instances of ndarray are not HashableNdarray, meaning they cannot be added to sets, nor used as keys in dictionaries. This is by design, ndarray objects are mutable, and therefore cannot reliably implement the __hash__() method.
The HashableNdarray class allows a way around this limitation. It implements the required methods for HashableNdarray objects in terms of a array ndarray object. This can be either a copied instance (which is safer) or the original object (which requires the user to be careful enough not to modify it).
- Parameters:
array (ndarray) – The array that must be array.
copy (bool) –
Whether the array is copied.
By default it is set to False.
- copy_wrapped_array()[source]¶
Wrap a copy of the original array if it was not yet.
- Return type:
None