Hi, Basically I want to put my responses for each of the outputs of my loop (answers yes or no to different contrast numbers) into an empty list ... so I would have a list for each contrast corresponding to how many yes or no's there were?

from observerClass import observer
import numpy

obs1 = observer(0.2, 0.05)
obs2 = observer(0.1,0.05)

for cont in numpy.linspace(0.0,1.0,10):
    print 'cont is', cont 
    for repN in range(10):    
        print cont, obs1.getResponse(cont)  <--- this generates a yes or no to the cont

Any help would be much appreciated!

Edited 4 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

print(sum(obs1.getResponse(cont) == 'yes' for cont in numpy.linspace(0.0, 1.0, 10)))

Edited 4 Years Ago by pyTony: n/a

print(sum(obs1.getResponse(cont) == 'yes' for cont in numpy.linspace(0.0, 1.0, 10)))

Thanks, that works for part of what I want but I dont think I was very clear. I have set it so that I get a yes or no answer to each contrast. I want to store the amount of yes and no's for each contrast in a list ... if that makes any sense?

So I would get something like ... Contrast 0.2 (yes 8, no 10)
Contrast 0.5 (yes 10, no 1)

Can you post exact output of your program as it is, to know what data you are working with, as we have not the observerClass module to know it. Have you considered using collections.Counter?

Edited 4 Years Ago by pyTony: n/a

""observer class to be imported by other scripts
"""
import random

class observer:
    def __init__(self, thresh, noise):
        self.thresh=thresh
        self.noise=noise
    
    def getResponse(self, contrast):
        if contrast>(self.thresh+self.noise):
            return 'yes'
        elif contrast<(self.thresh-self.noise):
            return 'no'
        else:
            if random.random()>0.5:
                return 'yes'
            else:
                return 'no'

Edited 4 Years Ago by Narue: added code tags

Something like this?

from observerClass import observer
import numpy
import collections

obs1 = observer(0.2, 0.05)
obs2 = observer(0.1,0.05)
stats = [(cont, collections.Counter(obs1.getResponse(cont) for repN in range(10)))
for cont in numpy.linspace(0.0,1.0,10)]
This article has been dead for over six months. Start a new discussion instead.