Grasshopper

algorithmic modeling for Rhino

Replacing descending in Ascending order of the list

Hello hoppers,

I have a simple doubt, probably this could be solved in an easier way. Consider a list with numbers (0,1,2,3,5,8,2,3,4,5,6,7,8,9,10,11) , here you can see the numbers ascend but descend in middle of the list. I need to replace the descending numbers(2,3,4,5,6,7) with previous number 8 so the resulting list can be (0,1,2,3,5,8,8,8,8,8,8,8,8,9,10,11). 

May I know how it can be done? both grasshopper components and python scripts are acceptable. Thank you very much in advance.

Views: 1135

Replies to This Discussion

Here's a solution purely in GH. Basic idea is cut the entire list of N items into N sublists, with the first sublist containing only the first item, the second sublist only the first two, the third sublist only the first three etc. 

Then, for each sublist, find the highest value and copy that into the appropriate spot in the final list:

Attachments:

Wow!! Thanks a lot David, this literally made me to reduce lot of grasshopper components which I made earlier. I love viewing the changes in the graph. Compact and neat.

In Python you might do something like this:

Attachments:

Amazing Anders, you are the real mvp, will defintely use this for lists.

Sweet. Had a bit of a brain fart though, skipping the first element in range() is cleaner:

hello Anders, another question, how would you add these identical numbers with another range.

For Example if a = [2,4,5,3,1,7,8] and the script gives output as [2,4,5,5,5,7,8] but I need this descending numbers (3,1) to be (5 + range), where range will be (1,1.5,1.7,1.9,2) so here only two numbers are descending which is (3,1) so this will change to ((5+1), (5+2)) taking only first and last from range, so final output will be [2,4,5,6,7,7,8] . Can you help me with this, I have tried and still trying to figure it out. Thanks in advance.

Simply add the increment value, like so (if I understood you correctly):

Amazing! a bow to you sir.. I was adding list name where y = [1,2,3] which is range values..

for i in range(1,len(a)):
if a[i-1] > a[i]:
a[i] = a[i-1] + y 

so Error

I lost touch with python, have to recall it. Again, Thank you very much. Simple and Neat yet Brilliant.

May I know how to predict the range. like if a = [2,4,5,7,4,3,1,8,10]
here the descending numbers (4,3,1) is between two ascending numbers (7,8) so range should be between them so output can be [2,3,4,7,7.25,7.5,7.75,8,10] . I figured doing it with grasshopper components but python might reduce the work with loops. Thanks in advance.

Not sure I understand, but, changing the increment value to 0.25:

sorry for briefly explaining. Now I have a list where

 a = [2,4,5,7,4,3,1,8,10] so increment can be 0.25 because only 3 values inbetween 7 and 8 but what if list is a = [2,4,5,7,5,4,3,1,8,10] now number of descending values is 4 so now range should be (7.2, 7.4, 7.6, 7.8) in place of descending values so output will be [2,4,5,7,7.2, 7.4, 7.6, 7.8,8,10]

I need it to be parametric like if descending values are more or less it should convert those into range between those ascending values (7,8) 

For 4 descending its (7.2, 7.4, 7.6, 7.8)

For 10 its (7.1, 7.2, 7.3 , 7.4 , 7.5, 7.6, 7.7, 7.8, 7.9) so on. Hope this clears up. It should predict number of descending values and convert it into range.

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