Advertisement
smathot

Untitled

Feb 9th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. import numpy as np
  2.  
  3. repeatCheck = 3 # # How many repeats are not *allowed*
  4. column = 3 # Which column should be checked for repeats
  5. src = 'stimlist.csv' # A tab separated text file in the file pool
  6.  
  7. # Load the conditions into a NumPy array
  8. a = np.loadtxt(exp.get_file(src), delimiter='\t', dtype=str)
  9.  
  10. # Go into a 'shuffle loop'
  11. while True:
  12.     # Shuffle the array
  13.     np.random.shuffle(a)
  14.    
  15.     # Loop from trial 0 to (number-of-trials - repeatCheck).
  16.     shuffleAgain = False
  17.     for i in range(len(a)-repeatCheck):
  18.         # Get a slice out of the condition matrix that goes from i to
  19.         # i+repeatCheck, including only the specified column
  20.         slice = a[i:i+repeatCheck, column]
  21.         # If the length of the list of unique items in that slice is 1
  22.         # (i.e. if they are all the same), we need to shuffle the
  23.         # list again
  24.         if len(np.unique(slice)) == 1:
  25.             shuffleAgain = True
  26.     # If we don't need to shuffle again, exit the 'shuffle loop'
  27.     if not shuffleAgain:
  28.         break
  29. # Store the array as exp.stimlist, so we can access it later on
  30. exp.stimlist = a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement