Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I get the same results in Python 2.6.6 and numpy 1.3.0. According to <a href="http://docs.python.org/glossary.html#term-hashable">the Python glossary</a>, an object should be hashable if <code>__hash__</code> is defined (and is not <code>None</code>), and either <code>__eq__</code> or <code>__cmp__</code> is defined. <code>ndarray.__eq__</code> and <code>ndarray.__hash__</code> are both defined and return something meaningful, so I don't see why <code>hash</code> should fail. After a quick google, I found <a href="http://osdir.com/ml/python.scientific.devel/2005-09/msg00035.html">this post on the python.scientific.devel mailing list</a>, which states that arrays have never been intended to be hashable - so why <code>ndarray.__hash__</code> is defined, I have no idea. Note that <code>isinstance(nparray, collections.Hashable)</code> returns <code>True</code>.</p> <p>EDIT: Note that <code>nparray.__hash__()</code> returns the same as <code>id(nparray)</code>, so this is just the default implementation. Maybe it was difficult or impossible to remove the implementation of <code>__hash__</code> in earlier versions of python (the <code>__hash__ = None</code> technique was apparently introduced in 2.6), so they used some kind of C API magic to achieve this in a way that wouldn't propagate to subclasses, and wouldn't stop you from calling <code>ndarray.__hash__</code> explicitly?</p> <p>Things are different in Python 3.2.2 and the current numpy 2.0.0 from the repo. The <code>__cmp__</code> method no longer exists, so hashability now requires <code>__hash__</code> and <code>__eq__</code> (see <a href="http://docs.python.org/py3k/glossary.html#term-hashable">Python 3 glossary</a>). In this version of numpy, <code>ndarray.__hash__</code> is defined, but it is just <code>None</code>, so cannot be called. <code>hash(nparray)</code> fails and<code>isinstance(nparray, collections.Hashable)</code> returns <code>False</code> as expected. <code>hash(vector)</code> also fails.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload