hashval and Numpy

Uwe Schmitt uwe at rocksport.de
Wed Oct 17 15:23:53 CEST 2001


Emile van Sebille <emile at fenx.com> wrote:
| How about:

|>>> a
| array([3, 4])
|>>> `a`
| 'array([3, 4])'
|>>> ky = `Numeric.array((3,4))`
|>>> ky
| 'array([3, 4])'

| Not ideal, but would work in a pinch.  ;-)

shurely it's possible to assign each array an hashval. this can be
done by converting an array to a tuple (or a tuple of tuples in the
2d case). but: how can i expand numpy, such that a hashval is
considered.
i tried 

     Numeric.array.__hash__ = lambda x: hash(tuple(x))

but i get

"object has readonly attributes"....

greetings, uwe.

| ---------
| "Uwe Schmitt" <uwe at rocksport.de> wrote in message
| news:9qhksb$6raii$1 at hades.rz.uni-sb.de...
|> Hi,
|>
|> I'd like to use a dictionary with NumericalPython-arrays as keys.
|> This does not work, because NumPy does not provide hashvals for
|> arrays. But this could be easyly done, as tupels are hashable.
|> So: how can I extend NumPy, so that arrays get a hashval ???
|>
|> Greetings, Uwe.
|>
|> --
|> Uwe.Schmitt at num.uni-sb.de      Universität des Saarlandes
|> phone: +49 (0)681/302-2468     Geb. 36.1, Zi. 4.17, PF 151150
|>                                D-66041  Saarbrücken
|> http://www.rocksport.de        http://www.rocksport.de/first_ride.mp3
|>


-- 
Uwe.Schmitt at num.uni-sb.de      Universität des Saarlandes
phone: +49 (0)681/302-2468     Geb. 36.1, Zi. 4.17, PF 151150
                               D-66041  Saarbrücken
http://www.rocksport.de        http://www.rocksport.de/first_ride.mp3




More information about the Python-list mailing list