. Advertisement .
..3..
. Advertisement .
..4..
How to solve the problem – typeerror: unhashable type: ‘numpy.ndarray’? I have the detail here:
above = range(18000, 18060, 5)
data = np.loadtxt(open('data.txt'), delimiter=None)
energies = (np.hsplit(data, 3))[0]
slice = set(energies)&set(above)
While I run it, I found the warning message:
Traceback (most recent call last):
File "<pyshell#27>", line 1, in <module>
set(energies)&set(above)
TypeError: unhashable type: 'numpy.ndarray
That is my question in my midterm exam, and it is urgent. I searched the solutions on some websites, but I don’t get it. I may miss any line or other changes. I appreciate your assistance!
The cause: The variable
energies
likely have unacceptable shape:Solution:
Instead of writing by your approach:
Probably you use this way:
numpy.ndarray
can contain any element, e.g.int
,float
,string
etc. If necessary, check the type and convert.