Grasshopper

algorithmic modeling for Rhino

Hello

I wrote simple script to assign hourly weather data (only some hours were recorded) to hours. If there was no measurement it should return 0. It should work like this (example with similar values):

leadList = [501,502,503,504,505,506]
patternList = [502,503,506]
editList = [wData1,wData2,wData3]
finList = []

def assignData(i,y):
  for i < len(leadList):
    if leadList[i] == patternList[y]:
      finList.append(editList[y])
      i += 1
      y += 1
    else:
      finList.append(0)
      i += 1
    assignData(i,y)

i = 0
y = 0
assignData(i,y)

which returns

[0,wData1,wData2,0,0,wData3]

My record has about 43000 values and RhinoWIP crashes every time I try to evaluate the whole list. But it works perfectly for smaller parts of my list. Can someone help me, please? 

Views: 314

Attachments:

Replies to This Discussion

Recursive functions are memory intensive. For what you're trying to do you can use other solutions. Here is an example:

from collections import defaultdict
from itertools import izip


leadList = [501, 502, 503, 504, 505, 506]
patternList = [502, 503, 506]
editList = ['wData1', 'wData2', 'wData3']

d = defaultdict(int)  # default value of int is 0


# assign the availabe values
for k, v in izip(patternList, editList):
    d[k] = v

# get the final list
finList = [d[i] for i in leadList]

print finList
# [0, 'wData1', 'wData2', 0, 0, 'wData3']

I tried and it works like a charm. Now I need to google and leard what the script actually does. Thanks for your help! 

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