gemseo / algos

Hide inherited members

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).

  • array (ndarray) – The array that must be array.

  • copy (bool) –

    Whether the array is copied.

    By default it is set to False.


Wrap a copy of the original array if it was not yet.

Return type:



Return the array ndarray.


The array ndarray, or a copy if the wrapper is copy.

Return type:


property is_copy: bool

Whether the wrapped_array array as a copy of the original one.

property wrapped_array: ndarray

The wrapped_array array.