Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

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 a question.

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.

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

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • 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
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8200159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:20:37+00:00 2026-06-07T06:20:37+00:00

I am trying to create a dictionary from a relatively large numpy array. I

  • 0

I am trying to create a dictionary from a relatively large numpy array. I tried using the dictionary constructor like so:

elements =dict((k,v) for (a[:,0] , a[:,-1]) in myarray)

I am assuming I am doing this incorrectly since I get the error: "ValueError: too many values to unpack"

The numPy array looks like this:

[  2.01206281e+13  -8.42110000e+04  -8.42110000e+04 ...,   0.00000000e+00
    3.30000000e+02  -3.90343147e-03]

I want the first column 2.01206281e+13 to be the key and the last column -3.90343147e-03 to be the value for each row in the array

Am I on the right track/is there a better way to go about doing this?

Thanks

Edit: let me be more clear I want the first column to be the key and the last column to be the value. I want to do this for every row in the numpy array

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:20:39+00:00Added an answer on June 7, 2026 at 6:20 am

    This is kind of a hard question on answer without knowing what exactly myarray is, but this might help you get started.

    >>> import numpy as np
    >>> a = np.random.randint(0, 10, size=(3, 2))
    >>> a
    array([[1, 6],
           [9, 3],
           [2, 8]])
    >>> dict(a)
    {1: 6, 2: 8, 9: 3}
    

    or

    >>> a = np.random.randint(0, 10, size=(3, 5))
    >>> a
    array([[9, 7, 4, 4, 6],
           [8, 9, 1, 6, 5],
           [7, 5, 3, 4, 7]])
    >>> dict(a[:, [0, -1]])
    {7: 7, 8: 5, 9: 6}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a dictionary from 2 lists where one list contains
Alright well I am trying to create a dictionary from a text file so
I'm trying to create a Dictionary with array of integer, string and boolean data
I'm trying to create a .resx file from a dictionary of strings. Luckily the
I'm trying to create a dictionary of words from a collection of files. Is
I am trying to create a dictionary from a csv file. The first column
I am trying to create a Python dictionary from a stored list. This first
I'm trying to use LINQ to create a new dictionary from an existing one,
I am trying to create a dictionary from a list and tuple of tuples
I'm trying to create a dictionary type - ie hash table with a string

Explore

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

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

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.