Grasshopper

algorithmic modeling for Rhino

Sorting set of data by value while keeping the original index

Hi All,

I'm wondering what is the easiest way to filter and sort a set of real numbers by their value while keeping their original index number. The purpose of the exercise is to pick certain objects out of a larger set based on some attributes, and then be able to find them in the original list, using the index number.

Here is the example: I created a large set of geometries. then I created a list from their volumes. My approach was to take this list and use "Dispatch" tool to filter and then rank results. First problem; I don't know how exactly I should write the expression for F(x) that filters results for " x < 10000 ".  Second I don't know how to keep the original index numbers in the two resulting lists. I would like these original indexes to refer to the same values even after I sort them by their value.

I appreciate any help.

Best,

Yavar

Views: 7147

Replies to This Discussion

Hi Yavar,

there's two common ways to approach this.

  1. Create the indices as a list of integers. You can use [List Length] and [Series] to create this list. Then, sort both your numeric values and your indices synchronously, i.e. using the same Sort component. You then still know which numbers came from which index.
  2. Sort your numbers and do whatever else you need to do (but don't change them). Then use [Item Index] to figure out where they used to be stored in the original list. But for this approach it is vital you do not modify the numbers in any way, or they will become different numbers and [Item Index] won't work any more.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks David. I tired the first method and it worked beautifully.

Yavar

Hi.

Trying to implement the second version without changing the numbers doesn't seem to work:

What am I missing?

Cheers,

Eirik

For this to work you would need to put the Distance output into synchronous A Sort and then Sort A output into L List Item

Alternatively use Find Similar Member instead of List Index

Hi Danny, and thanks for your reply.

I solved it like this:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service