python lambda example


/ Published in: Python
Save to your folder(s)

from activestate. not complete or tested but good ref


Copy this code and paste it in your HTML
  1. if bootstraps == 1:
  2. srri = lambda low, high, size: range(size)
  3. else:
  4. srri = scipy.random.random_integers
  5.  
  6. for boot in range(bootstraps):
  7. for r in range(n1):
  8. for c in range(n0):
  9. sample_size = trial_result[r][c].size
  10. choices = srri(0, sample_size-1, sample_size)
  11. meas_grid[r,c] = pylab.array(trial_result[r][c][choices],dtype=float).mean()
  12.  
  13. model_grid[:,:,:,boot], params[:,boot] = \
  14. process_grid(s0, s1, meas_grid)
  15.  
  16. #Instead of
  17. srri = scipy.random.random_integers
  18. if bootstraps == 1:
  19. for r in range(n1):
  20. for c in range(n0):
  21. meas_grid[r,c] = pylab.array(trial_result[r][c],dtype=float).mean()
  22.  
  23. model_grid[:,:,:,boot], params[:,boot] = \
  24. process_grid(s0, s1, meas_grid)
  25. else:
  26. for boot in range(bootstraps):
  27. for r in range(n1):
  28. for c in range(n0):
  29. sample_size = trial_result[r][c].size
  30. choices = srri(0, sample_size-1, sample_size)
  31. meas_grid[r,c] = pylab.array(trial_result[r][c][choices],dtype=float).mean()
  32.  
  33. model_grid[:,:,:,boot], params[:,boot] = \
  34. process_grid(s0, s1, meas_grid)
  35.  
  36. #OR
  37. srri = scipy.random.random_integers
  38. for boot in range(bootstraps):
  39. if bootstraps == 1:
  40. for r in range(n1):
  41. for c in range(n0):
  42. meas_grid[r,c] = pylab.array(trial_result[r][c],dtype=float).mean()
  43.  
  44. model_grid[:,:,:,boot], params[:,boot] = \
  45. process_grid(s0, s1, meas_grid)
  46. else:
  47. for r in range(n1):
  48. for c in range(n0):
  49. sample_size = trial_result[r][c].size
  50. choices = srri(0, sample_size-1, sample_size)
  51. meas_grid[r,c] = pylab.array(trial_result[r][c][choices],dtype=float).mean()
  52.  
  53. model_grid[:,:,:,boot], params[:,boot] = \
  54. process_grid(s0, s1, meas_grid)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.