Nov-04-2022, 05:44 AM
Hi I have doubt regarding randomizing images with equal probability.
I have 24 images and I want to generate 150 sets of 9 images from the 24 images without repetition in the same set.
I have two scripts as followed but I am not getting desired results.
Please check and help me with this.
'''
This script is used to generate condition files for 150 participants, where each participants is presented with 9 images
randomly drawn from a set of 24 images. Each of the images are eventually presented 50 times.
'''
I have 24 images and I want to generate 150 sets of 9 images from the 24 images without repetition in the same set.
I have two scripts as followed but I am not getting desired results.
Please check and help me with this.

'''
This script is used to generate condition files for 150 participants, where each participants is presented with 9 images
randomly drawn from a set of 24 images. Each of the images are eventually presented 50 times.
'''
# import the libraries needed import pandas as pd from numpy.random import shuffle from psychopy import core # list of images - currently with generic naming convention - researcher would need to change the names on line 14 # researcher needs to change it to the appropriate file names (i.e. file name + extension) # if images are in a subfolder, the path must also be included/specified e.g. stimuli/image1.jpg where stimuli is the name of the subfolder and image1.jpg is within it images = ['im1', 'im2', 'im3', 'im4', 'im5', 'im6', 'im7', 'im8', 'im9', 'im10', 'im11', 'im12', 'im13', 'im14', 'im15', 'im16', 'im17', 'im18','im19','im20','im21','im22','im23','im24'] # parameters ims_per_participant = 9 # since there are 24 images to use in total and each participant sees 9 randomly from this set n_participants = 150 # and it is projected that there will be 150 participants, with each image presented at least 50 times # repeat the splitting and randomising process 50 times for i in range(75): shuffle(images) # randomise the images p1 = {'images' : images[0:12]} # select the first 9 images p2 = {'images' : images[13:24]} # select the last 9 images ps = [p1, p2] # the resulting separated images for pi, p in enumerate(ps): # save the separated images by numbering them p = pd.DataFrame.from_dict(p) p.to_excel('condition_file_'+str(i+1)+'_part'+str(pi+1)+'.xlsx', index = False)#script2
import random #list of images images = ['im1', 'im2', 'im3', 'im4', 'im5', 'im6', 'im7', 'im8', 'im9', 'im10', 'im11', 'im12', 'im13', 'im14', 'im15', 'im16', 'im17', 'im18','im19','im20','im21','im22','im23','im24'] #using the sample() method for i in range(150): sample_images = random.sample (images,k = 9) #displaying random selections without #repetitions print(sample_images)