list - Python RuntimeError: maximum recursion depth exceeded in cmp -
i have complex data structure i'm trying process.
explanation of data structure: have dictionary of classes. key name. value class reference. class contains 2 lists of dictionaries.
here's simple example of data structure:
import scipy.stats class employee_salaries(object): def __init__(self,management, players, disparity): self.management = management self.players = players self.disparity = disparity # coach's salary 12 1st year , 11 2nd year mgmt1 = [{'coach':12, 'owner':15, 'team manager': 13}, {'coach':11, 'owner':14, 'team manager':15}] plyrs1 = [{'point guard': 14, 'power forward':16,},{'point guard':16, 'power forward':18}] nba = {} mgmt2 = [{'coach':10, 'owner':12}, {'coach':13,'owner':15}] plyrs2 = [{'point guard':17, 'power forward':14}, {'point guard': 22, 'power forward':16}] nba['cavs'] = employee_salaries(mgmt1,plyrs1,0) nba['celtics'] = employee_salaries(mgmt2,plyrs2,0) let's wanted determine disparity between point guard's salary , owner's salary on these 2 years.
for key, value in nba.iteritems(): x1=[]; x2=[] num = len(nba[key].players) in range(0,num): x1.append(nba[key].players[i]['point guard']) x2.append(nba[key].management[i]['owner']) tau, p_value = scipy.stats.kendalltau(x1, x2) nba[key].disparity = tau print nba['cavs'].disparity keep in mind not real data. in actual data structure, there on 150 keys. , there more elements in list of dictionaries. when run code above on real data, runtime error.
runtimeerror: maximum recursion depth exceeded in cmp error.
how can change code above doesn't give me maximum recursion depth error? want type of comparison , able save value.
you're passing in empty arrays, , function handles incorrectly. either update scipy, or skip if arrays empty (though check data isn't wrong , makes sense have empty array there).
some suggestions code.
for team in nba.itervalues(): #or `for name, team in nba.iteritems()` if use name. x1, x2 = [], [] # not `x1 = x2 = []`, since 2 names 1 list player, manager in izip(team.players, team.management): x1.append(player['point guard']) x2.append(manager['owner']) # or lose `for` loop , say: # `x1 = [player['point guard'] player in team.players]` # `x2 = [manager['owner'] manager in team.management]` # (this can more efficient.) tau, p_value = scipy.stats.kendalltau(x1, x2) team.disparity = tau print nba['cavs'].disparity
Comments
Post a Comment