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

  • Home
  • SEARCH
  • 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 7754377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:17:29+00:00 2026-06-01T12:17:29+00:00

I am looking for a function ideally in pure python that is similar to

  • 0

I am looking for a function ideally in pure python that is similar to numpy.argsort in that it returns only a list of sorted indices while leaving the original arrays untouched, yet it needs to be able to sort on data contained in multiple arrays.

Example:

>>> names = ['xavier', 'bob', 'billy', 'jene', 'samson']
>>> ages = [15, 32, 63, 32, 15]
>>>indexes = sort by ages and then by names
[4, 0, 1, 3, 2]
>>> for i in indexes:
>>>    print "Name", names[i]
>>>    print "Age", ages[i]

The sorting function cannot create extra data structures, meaning list comprehension or functions like zip are out of the question. Each array consists of 5 million objects, generating zipped version of the arrays explodes the memory requirements by a factor of at least 3. Using list comprehension such as sorted(..key=lambda x:(names[x],ages[x])) causes a slowdown such as the sort takes over a minute to complete (and the memory requirements to create these intermediary tuples)

So far, as long as I only want to sort on a single array it is fast enough, however since the indices list does not know about the other arrays, I am unable to call multiple “sort” operations as I would if I had a zipped version of the two lists.

  • 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-01T12:17:31+00:00Added an answer on June 1, 2026 at 12:17 pm

    I created my own solution that works great.

    Given the following data set:

    groups = reversed(range(5000000))
    ages = [random.randrange(0, 120) for x in groups]
    names = ['foobar-%d' % random.randrange(0, 5000) for x in groups]
    
    columns = dict(names=names,ages=ages,groups=groups)
    
    def sort_on(col):
        idxs = range(len(columns[col]))
        idxs.sort(key=lambda x:columns[col][x])
        return idxs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a function that will tell me, for a list of
Similar in concept to Math.Abs() - I'm looking for a function that when given
been looking but not much luck, i want to create a function that only
I'me looking for a function that would receive a time and would round it
I'm looking for a function that calculates years from a date in format: 0000-00-00.
I am looking for a function that would be the alphabetic equivalent of is_numeric.
I am Looking for a Function that insert Any form values to mysql ,
Original Question I am looking for a function that attempts to quantify how distant
I am looking for a way to call a function only after .each() finishes
Ideally I'm looking for a Javascript resource loader that will: (1) Allow me to

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.