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 7019011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:07:37+00:00 2026-05-27T23:07:37+00:00

I have a large (in thousands) collection of word : value (float) pairs. I

  • 0

I have a large (in thousands) collection of word : value (float) pairs. I need to find the best of the value and extract the corresponding associated word. For example, I have (a,2.4),(b,5.2),(c,1.2),(d,9.2),(e,6.3),(f,0.4). I would like (d,9.2) as the output.

Currently, I am using a dictionary to store these tuples and use the max operator to retrieve the maximum key value in the dictionary. I was wondering if a numpy array would be more efficient. Soliciting expert opinions here.

  • 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-05-27T23:07:38+00:00Added an answer on May 27, 2026 at 11:07 pm

    Using Numpy here would involve keeping the float values in a separate ndarray. Find the index of max value using argmax and get the word from a separate list. This is very fast, but constructing the ndarray only to find the max is not. Example:

    import numpy as np
    import operator
    
    names = [str(x) for x in xrange(10000)]
    values = [float(x) for x in xrange(10000)]
    tuples = zip(names, values)
    dic = dict(tuples)
    npvalues = np.fromiter(values, np.float)
    
    def fa():
        return names[npvalues.argmax()]
    
    def fb():
        return max(tuples, key=operator.itemgetter(1))[0]
    
    def fc():
        return max(dic, key=dic.get)
    
    def fd():
        v = np.fromiter((x[1] for x in tuples), np.float)
        return tuples[v.argmax()][0]
    

    Timings: fa 67 µs, fb 2300 µs, fc 2580 µs, fd 3780 µs.

    So, using Numpy (fa) is over 30 times faster than using a plain list (fb) or dictionary (fc), when the time to construct the Numpy array is not taken into account. (fd takes it into account)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large JTree and I need to expand thousands of nodes all
I have several large csv files with thousands of columns that I need to
I have large json data which is contains hundreds thousands elements, now i need
Background I have a large collection (~thousands) of sequences of integers. Each sequence has
How large does a collection have to be for std::map to outpace a sorted
I have thousands of large sets of tag cloud data; I can retrieve a
I have some .sql files with thousands of INSERT statements in them and need
I have a third party C code which has large arrays of type float
I have a WCF service handling a very large number of requests (thousands per
I have a large live database. What are the best practices for making schema

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.