[SciPy-user] usings numpy arrays in sets

Francesc Alted faltet@pytables....
Thu Jun 25 12:53:43 CDT 2009


A Thursday 25 June 2009 19:33:27 Robert Kern escrigué:
> > Hmm, now that I think about this, I ask myself if it would not be useful
> > to implement a functional `__hash__()` method for read-only arrays.
> >  Perhaps there is a show stopper for that, but I can't see it.
>
> Even if the memory is not writable from your array doesn't mean that
> it isn't being modified from another.
>
> In [1]: a = arange(10)
>
> In [2]: b = a[:]
>
> In [3]: b.flags.writeable = False
>
> In [4]: b
> Out[4]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>
> In [5]: a[3:7] = 10
>
> In [6]: a
> Out[6]: array([ 0,  1,  2, 10, 10, 10, 10,  7,  8,  9])
>
> In [7]: b
> Out[7]: array([ 0,  1,  2, 10, 10, 10, 10,  7,  8,  9])

Yep.  However, one could also check for the array owning the data, and if 
true, then we can be pretty sure that the array is immutable.  I like the idea 
of having hasheable arrays; they can be handy in some scenarios.

-- 
Francesc Alted


More information about the SciPy-user mailing list