为三个项目生成固定值,而不是randrange

时间:2018-05-29 16:52:07

标签: python

此前的代码工作,但是,现在我想生成35,155和215度的固定方向,并尝试生成相隔60度的伪随机方向。当前代码的问题是值可能重复或太靠近。

from psychopy import visual, event, misc, core, sound, gui, data
from sys import argv
from math import sin, cos
import numpy as np
import numpy.random as rand
import sys,os, datetime as dt
import random
import csv
from psychopy.tools.filetools import fromFile

all_ori=[]#create distractor variable for storing distractor orientations. want to save all orientations
for s,this_stim in enumerate(stims): #loop over stimuli
    this_stim.setFillColor(-1) #make sure that all stimuli fill color are black (when they are cued, they are white)
    if vis == 'left':
        current_x,current_y  = eccen * np.cos(left_polar[s]),eccen * np.sin(left_polar[s]) #convert polar positions to x,y
    elif vis == 'right':
        current_x,current_y  = eccen * np.cos(right_polar[s]),eccen * np.sin(right_polar[s])
    this_stim.setPos([current_x,current_y]) #set position of current stimulus to current_x, current_y
    this_orient = random.randrange(0, 179) #randomly choose orientation and set stimulus to this orientation (previous)
    all_ori.append(this_orient)
    this_stim.setOri(this_orient)
    print all_ori #--- how you can determine if code is working
    this_stim.draw() #draw stimulus

1 个答案:

答案 0 :(得分:0)

Numpy Random Choice can pick from a list
试试这个:
    rand.choice([35,155,215])