[我想做的是向参加者展示动物的话语和动物的形象。有时单词和图像会匹配,有时会不匹配,参与者必须回答动物的名字。我正在努力的是呈现文本和图像。
所以...
我有动物清单:
animal_words =[ 'gorilla', 'Ostrich', 'Snake', 'Panda']
然后我得到了与上面的颜色相同的动物图像
animal_image=[ 'gorilla', 'Ostrich', 'Snake', 'Panda']
我有两个条件:相同和不同。我将以上列表分为相同和不同的类别。相同的条件将被呈现给参与者10次,不同的条件将被呈现5。我将它们放到了试验列表中。
same=[]
different[]
conditions=[]
for animal in animals:
for image in animal_images:
if animal == image:
same.extend([[animal,image]]* 10)
else:
different.extend ([[animal,image]] * 5)
shuffle (same)
shuffle (different)
#combine conditions into trial list
conditions=[same,different]
具有相同条件的示例是:
[[大猩猩(文字),大猩猩(图像)]
然后我创建窗口和刺激:
from psychopy import visual, event, core, gui
win=visual.Window([1024,768], fullscr=False,allowGUI=True, units='pix',\
color= (-1,-1,-1))
tstim=visual.TextStim(win, text='', pos=(0,0), color= ((0,0,0)))
imstim=visual.ImageStim(win, image='', pos=(0,0)
我需要做的是将动物文本分配给tstim,将动物图像分配给imstim并设置一个循环,以便它们根据我创建的列表进行更改。由于列表卡在一起,因此我无法成功执行此操作。我也不知道如何设置循环以下代码是我对循环外观的最佳猜测:
for a in conditions:
tstim.setText(animal_name)
imstim.setImage(animal_image)
tstim.draw()
imstim.draw()
win.flip()
core.wait()
但是,我认为该循环不正确,但我再也没有其他想法。任何帮助,将不胜感激
您走在正确的轨道上。有一个嵌套列表是一个好主意,其中每个子列表都包含该试验对。我建议创建一个包含图像和文本刺激的嵌套列表,然后遍历该刺激列表。我在下面(未经测试)对此进行演示。
import random
from psychopy import visual, event, core, gui
animal_words = ['Gorilla', 'Ostrich', 'Snake', 'Panda']
animal_images = ['Gorilla', 'Ostrich', 'Snake', 'Panda']
win = visual.Window(
[1024, 768], fullscr=False, allowGUI=True, units='pix',
color=(-1, -1, -1))
# Create list of trials
trials = []
for animal in animal_words:
for image in animal_images:
# Get the filepath to the animal image.
image_file = "{}.png".format(image)
# Instantiate the stimulus objects.
stim_pair = [
visual.TextStim(win, text=animal, pos=(0, 0), color=(0, 0, 0)),
visual.ImageStim(win, image=image_file, pos=(0, 0))
]
# Add stimulus objects to growing list of trials.
if animal == image:
trials.extend([stim_pair] * 10)
else:
trials.extend([stim_pair] * 5)
random.shuffle(trials)
# Run trials
for text, image in trials:
text.draw()
image.draw()
win.flip()
core.wait()
如果所有试验都相同(只是顺序不同),则可以将文本和图像文件路径保存在电子表格中,将电子表格读取到列表中,创建刺激对象,然后重新整理该列表。这将代替在每次运行时创建列表。