【问题标题】:Duplicating random visual stimuli in Python/Psychopy在 Python/Psychopy 中复制随机视觉刺激
【发布时间】:2016-01-13 15:49:30
【问题描述】:

使用 Python/Psychopy。我向屏幕中心呈现 3 个随机视觉刺激 1 秒(imgList1)。然后,我在屏幕的右上角 (imgList) 呈现 3 个其他随机视觉刺激。在 50% 的情况下,我需要第二组刺激(imgList)与第一组(imgList1)相同。我如何访问在第 1 部分随机选择的刺激,以便之后我可以使用该信息显示相同的刺激?我不确定如何跟踪我最初随机选择的图像的结果。

这是我的代码:

#make initial stimuli
imgList1 = glob.glob(os.path.join('stim','*.png'))
random.shuffle(imgList1)
targetset = [visual.ImageStim(window, img) for img in imgList1]

setlocation = [(-2,0),(0,0),(2,0)]
random.shuffle(setlocation)

#make second group of stimuli
imgList = glob.glob(os.path.join('stim', '*.png'))
random.shuffle(imgList)
pics = [visual.ImageStim(window, img) for img in imgList[:3]]

location = [(1,2),(3,3),(5,5)]
random.shuffle(location)

#display initial stimuli set
for i in range(3):
    targetset[i].pos = setlocation[i]
    targetset[i].draw()

window.flip()
core.wait(1)

#display secondary stimuli
for i in range(3):
    pics[i].pos = location[i]
    pics[i].draw()
    window.flip()
    core.wait(.25)

core.wait(3)
window.close()
quit()

【问题讨论】:

    标签: python random psychopy


    【解决方案1】:

    targetset 是包含您从 imgList1 中选择的图像的列表。当您绘制它们时,它们不会去任何地方。您以后仍然可以访问该列表(只要您不删除或覆盖)。只需掷硬币(选择 0 和 1 之间的随机数并检查是否小于 0.5。如果是,则在辅助刺激中使用 pics,如果不使用 targetset(带有第二个位置列表)。您可能会发现这值得抽象成一个函数。

    def drawSet (imgs,locs):
        for(i,l) in (imgs,locs):
            i.pos = l
            i.draw()
            window.flip()
            core.wait(0.25)
    

    然后你可以将它用于drawSet(targetset,setlocation)drawSet(pics,location)drawSet(targetset,location) 随机(假设你在某处import random as r

    if r.random() < 0.5:
        drawSet(pics,location)
    else:
        drawSet(targetset,location)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-12
      • 2023-03-31
      • 2023-01-01
      相关资源
      最近更新 更多