close

[Solved] TypeError: unhashable type: ‘numpy.ndarray’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error TypeError: unhashable type: ‘numpy.ndarrayin python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How TypeError: unhashable type: ‘numpy.ndarray’ Error Occurs?

Today I get the following error TypeError: unhashable type: ‘numpy.ndarrayin python.

How To Solve TypeError: unhashable type: ‘numpy.ndarray’ Error ?

  1. How To Solve TypeError: unhashable type: 'numpy.ndarray' Error ?

    To Solve TypeError: unhashable type: 'numpy.ndarray' Error numpy.ndarray can contain any type of element, e.g. intfloatstring etc. Check the type an do a conversion if neccessary.

  2. TypeError: unhashable type: 'numpy.ndarray'

    To Solve TypeError: unhashable type: 'numpy.ndarray' Error numpy.ndarray can contain any type of element, e.g. intfloatstring etc. Check the type an do a conversion if neccessary.

Solution 1


Your variable energies probably has the wrong shape:

>>> from numpy import array
>>> set([1,2,3]) & set(range(2, 10))
set([2, 3])
>>> set(array([1,2,3])) & set(range(2,10))
set([2, 3])
>>> set(array([[1,2,3],])) & set(range(2,10))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'numpy.ndarray'

And that’s what happens if you read columnar data using your approach:

>>> data
array([[  1.,   2.,   3.],
       [  3.,   4.,   5.],
       [  5.,   6.,   7.],
       [  8.,   9.,  10.]])
>>> hsplit(data,3)[0]
array([[ 1.],
       [ 3.],
       [ 5.],
       [ 8.]])

Probably you can simply use

>>> data[:,0]
array([ 1.,  3.,  5.,  8.])

instead.

(P.S. Your code looks like it’s undecided about whether it’s data or elementdata. I’ve assumed it’s simply a typo.)

Solution 2

numpy.ndarray can contain any type of element, e.g. intfloatstring etc. Check the type an do a conversion if neccessary.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read