有没有办法生成出现在随机位置的图像对象,但必须是出现在 12 个可能的干扰位置之一的目标?
问问题
1299 次
2 回答
0
迈克尔是对的,更多信息会很有用,但如果我理解你的话,请尝试这样的事情:
1/ 将自定义代码对象添加到您的试用循环中
2/ 在“开始实验”选项卡中:
import random, copy
from random import randint
from decimal import *
# setup an array to store 6 locations to randomly allocate to our shapes
# (or select random locations between (-1,-1) and (1,1) if you want them completely
# random though you then need to factor in overlaying shapes)
master_positions=[[0.2,0.6],[0.2,0],[0.2,-0.6],[0.6,0.6],[0.6,0],[0.6,-0.6]]
positions = copy.deepcopy(master_positions)
3/ 在“开始例程”选项卡中:
# reset 'positions'
positions = copy.deepcopy(master_positions)
#randomise this for each trial
random.shuffle(positions)
4 / 然后,在您的对象的图像/多边形(或其他)上,而不是硬编码(x,y)坐标,而是引用位置变量。请记住将其右侧的下拉菜单选项从“恒定”更改为“设置每次重复”,例如
$positions[3]
因此,如果您有 6 个对象要随机定位,则使用$positions[0] .. [5]
, 每个对象一个
你也可以做类似的事情来改变大小、颜色……。
希望这可以为您提供要点。关于干扰位置,您可以有 2 个数组来存储位置而不是一个,并从干扰列表中随机选择一个以每次使用。
于 2014-10-21T09:01:34.537 回答
0
如果我正确理解您的问题,您有 12 个刺激物要放置在随机位置,其中一个图像(随机选择)需要出现在一组固定位置中的一个位置(随机选择)。
我认为正确的方法是首先生成您的刺激位置,然后将每个位置分配给一个图像:
import numpy as np
# define fixed locations
fixedlocations=np.array([[100,10],
[-50,20],
[10,50]])
# define window constants
winx = 500
winy = 400
# get list of random locations
locations = np.random.uniform(low = -1,high = 1, size = [12,2])
# scale locations to window size
locations[:,0] *= winx
locations[:,1] *= winy
# i think psychopy requires integers for coordinates
locations = locations.round()
# pick a random fixed location and insert into the random locations
whichrandom = np.random.randint(low=0, high=12)
whichfixed = np.random.randint(low=0, high=2)
# substitute a random fixed location in at a random row
locations[whichrandom,:] = fixedlocations[whichfixed,:]
我所做的只是在窗口中随机生成一组 12 个可能的位置,然后用从固定集中随机选择的位置替换一个(随机选择的)位置。
然后,您可以使用 for 循环为每个刺激分配位置。如果您的刺激在列表中,您可以执行以下操作:
for i in range(12):
mystimuli[i].setPos(locations[i,:])
于 2015-01-27T00:48:22.250 回答