[SciPy-user] usings numpy arrays in sets
Robert Kern
robert.kern at gmail.com
Thu Jun 25 13:33:27 EDT 2009
On Thu, Jun 25, 2009 at 08:04, Francesc Alted<faltet at pytables.org> wrote:
> A Thursday 25 June 2009 13:12:44 nicky van foreest escrigué:
>> Dear Francesc,
>>
>> Thanks. Your second suggestion works really nicely! I also thought
>> about the first solution, converting arrays to strings, but even emtpy
>> strings come with a memory penalty of 40 bytes (on my machine).
>
> 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])
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the SciPy-User
mailing list