Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- repeatCheck = 3 # # How many repeats are not *allowed*
- column = 3 # Which column should be checked for repeats
- src = 'stimlist.csv' # A tab separated text file in the file pool
- # Load the conditions into a NumPy array
- a = np.loadtxt(exp.get_file(src), delimiter='\t', dtype=str)
- # Go into a 'shuffle loop'
- while True:
- # Shuffle the array
- np.random.shuffle(a)
- # Loop from trial 0 to (number-of-trials - repeatCheck).
- shuffleAgain = False
- for i in range(len(a)-repeatCheck):
- # Get a slice out of the condition matrix that goes from i to
- # i+repeatCheck, including only the specified column
- slice = a[i:i+repeatCheck, column]
- # If the length of the list of unique items in that slice is 1
- # (i.e. if they are all the same), we need to shuffle the
- # list again
- if len(np.unique(slice)) == 1:
- shuffleAgain = True
- # If we don't need to shuffle again, exit the 'shuffle loop'
- if not shuffleAgain:
- break
- # Store the array as exp.stimlist, so we can access it later on
- exp.stimlist = a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement