Repository: sympy/sympy

Issue:
Python3-only: simplify with numpy.array fails with unhashable type: 'ImmutableDenseNDimArray'
Simplifying expressions with `numpy.array`s works in Python 2, but _not_ Python 3.

MWE:
```python
import numpy
import sympy


class dot(sympy.Function):
    pass


a = numpy.array([1, 2, 3])
x = sympy.Symbol('x')

expr = dot(x, a)
print(expr)
sympy.simplify(expr)
```
Error message:
```
Traceback (most recent call last):
  File "b.py", line 15, in <module>
    sympy.simplify(expr)
  File "/usr/lib/python3/dist-packages/sympy/simplify/simplify.py", line 514, in simplify
    original_expr = expr = signsimp(expr)
  File "/usr/lib/python3/dist-packages/sympy/simplify/simplify.py", line 374, in signsimp
    e = sub_post(sub_pre(expr))
  File "/usr/lib/python3/dist-packages/sympy/simplify/cse_opts.py", line 20, in sub_pre
    e = e.xreplace(dict((a, Mul._from_args([S.NegativeOne, -a])) for a in reps))
  File "/usr/lib/python3/dist-packages/sympy/core/basic.py", line 1100, in xreplace
    value, _ = self._xreplace(rule)
  File "/usr/lib/python3/dist-packages/sympy/core/basic.py", line 1107, in _xreplace
    if self in rule:
  File "/usr/lib/python3/dist-packages/sympy/core/basic.py", line 110, in __hash__
    h = hash((type(self).__name__,) + self._hashable_content())
TypeError: unhashable type: 'ImmutableDenseNDimArray'
```
Tested with current master.

Discussion:

Patch:
diff --git a/sympy/tensor/array/ndim_array.py b/sympy/tensor/array/ndim_array.py
index 10e13bf8ef..36eb27719b 100644
--- a/sympy/tensor/array/ndim_array.py
+++ b/sympy/tensor/array/ndim_array.py
@@ -403,6 +403,9 @@ def adjoint(self):
 class ImmutableNDimArray(NDimArray, Basic):
     _op_priority = 11.0
 
+    def __hash__(self):
+        return Basic.__hash__(self)
+
 
 from sympy.core.numbers import Integer
 from sympy.core.sympify import sympify


Test patch:
diff --git a/sympy/tensor/array/tests/test_immutable_ndim_array.py b/sympy/tensor/array/tests/test_immutable_ndim_array.py
index 3ed9dc4301..6e4637e30f 100644
--- a/sympy/tensor/array/tests/test_immutable_ndim_array.py
+++ b/sympy/tensor/array/tests/test_immutable_ndim_array.py
@@ -355,3 +355,10 @@ def test_symbolic_indexing():
     raises(ValueError, lambda: Ms[i, -1])
     raises(ValueError, lambda: Ms[2, i])
     raises(ValueError, lambda: Ms[-1, i])
+
+
+def test_issue_12665():
+    # Testing Python 3 hash of immutable arrays:
+    arr = ImmutableDenseNDimArray([1, 2, 3])
+    # This should NOT raise an exception:
+    hash(arr)