I made a custom function that automatically generates a trial list.
But it doesn’t assign values correctly.
I think the problem is related the for loop I used in my function, or I think it could be the arguments I passed in to the function that caused the problem.
Here is my code:
def make_trials(trial_info, num_trial, stop_ratio): ''' Make trial list ''' trials =  num_stop = int(num_trial * stop_ratio) for i in range(num_trial): trials.append(trial_info) if i < int(num_trial*stop_ratio): trials[i]['go_stop'] = 1 else: trials[i]['go_stop'] = 0 #trials = sample(trials, len(trials)) return trials
trial_info is a dictionary containing trial information. So, if stop_ratio is 1/2 it should return a list that contains half of the element with ‘go_stop’ value of 1, and the remainder with ‘go_stop’ value of 0
test_trials = make_trials(test_info, 10, 1/2)
This returns a list in which all of its elements have ‘go_stop’ value of 1, or 0 sometimes.
How can I solve this problem?