Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

You must login to add post.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Passionable Logo Passionable Logo
Sign InSign Up

Passionable

Passionable Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • New Questions
  • Trending Questions
  • Must read Questions
  • Hot Questions
Home/ Questions/Q 9139
In Process
Alek Richter
  • 0
Alek RichterEnlightened
Asked: January 13, 20222022-01-13T13:44:48+00:00 2022-01-13T13:44:48+00:00

TypeError: unhashable type: ‘numpy.ndarray’

  • 0

From a text file containing three columns of data I want to be able to just take a slice of data from all three columns where the values in the first column are equal to the values defined in above. I then want to put the slice of data into a new array called slice (I am using Python 2.7)

above = range(18000, 18060, 5)

data = np.loadtxt(open('data.txt'), delimiter=None)

energies = (np.hsplit(data, 3))[0]

slice = set(energies)&set(above)

The above comes back with:

Traceback (most recent call last):
  File "<pyshell#27>", line 1, in <module>
    set(energies)&set(above)
TypeError: unhashable type: 'numpy.ndarray
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
    • Report
  • Share
    Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Alek Richter Enlightened
    2022-01-13T13:45:07+00:00Added an answer on January 13, 2022 at 1:45 pm

    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 “”, line 1, in
    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.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 4k
  • Best Answers 0
  • Users 3
  • Popular
  • Answers
  • Alek Richter

    How do I update/upgrade pip itself from inside my virtual ...

    • 2 Answers
  • Alek Richter

    Truth value of a Series is ambiguous. Use a.empty, a.bool(), ...

    • 2 Answers
  • Alek Richter

    What is a NullPointerException, and how do I fix it?

    • 2 Answers
  • Alek Richter
    Alek Richter added an answer Pandas DataFrame columns are Pandas Series when you pull them… January 13, 2022 at 2:21 pm
  • Alek Richter
    Alek Richter added an answer The handshake failure could have occurred due to various reasons:… January 13, 2022 at 2:19 pm
  • Alek Richter
    Alek Richter added an answer Mac OS X doesn't have apt-get. There is a package… January 13, 2022 at 2:18 pm

Top Members

Alek Richter

Alek Richter

  • 4k Questions
  • 1k Points
Enlightened
coinbaseprosupportnumber[Xsdwerfgtyujhnbgfderewqasdxz]

coinbaseprosupportnumber[Xsdwerfgtyujhnbgfderewqasdxz]

  • 2 Questions
  • 2 Points

Trending Tags

questin question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • New Questions
  • Trending Questions
  • Must read Questions
  • Hot Questions

© 2021 Passionable. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.