psychopy.org | Reference | Downloads | Github

Unable to randomly choose subset of items from a longer list

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10):
PsychoPy version (e.g. 1.84.x): Latest
Standard Standalone? (y/n) Y If not then what?:
What are you trying to achieve?:
I am trying to randomly choose a subset of items from a longer list to be presented on the screen. For example, I have a list 110 images, I want to randomly choose 55 from the list to present to a subject. I would like to do it in builder without custom code which according to Psychopy website I should be able to do easily.
What did you try to make it work?:
Please refer to the attache image.
What specifically went wrong when you tried that?:
It gave an error, list not iterable I think.


Include pasted full error message if possible. “That didn’t work” is not enough information.

Much thanks in advance
-Tenzin

Ooh, that line isn’t great advice. That example would actually just give you 4 floating point numbers, rather than nicely behaved integers, and even if you rounded them, you might get duplicates. You would be better off with something like this:

$np.random.choice(110, size = 55, replace = False)

Documentation here:

https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.random.choice.html

Can you let me know if that works, so I can update that help page accordingly?

1 Like

Can I copy paste the python code in the “Selected rows” input box ? I will give it a try and let you know. Thanks !