Logging no response when creating custom averaging variables

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Windows 11
PsychoPy version (e.g. 1.84.x): 2024.1.5
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
I am currently working on an experiment where I want participants to respond with either the ‘a’ or ‘l’ keys after stimulus presentation. If they do not respond within 4.5 seconds, the next trial commences. My issue is that I want to store average accuracy and reaction times for the participants and I currently cannot as if the participant does not make a response, the experiment crashes (I believe it logs response as None and thus the average cannot be calculated.

How can I get the data file to put 0 for accuracy (incorrect response) and 4.5 for reaction time for that trial.
My code begin experiment tab:
‘’‘test_corr =
test_rts =
run_experiment = 1
no_response_acc = 0
no_response_rt = 4.5’‘’

My code end routine tab:
‘’'#how to cope with max time
if cat_resp_2.keys == “a” or “l”:
test_corr.append(cat_resp_2.corr) #append accuracy
test_rts.append(cat_resp_2.rt)#append rt

if cat_resp_2.keys == None:
test_corr.append(no_response_acc)
test_rts.append(no_response_rt)

#average variables for accuracy and rt
test_rt_average = average(test_rts)
test_corr_average = average(test_corr)

#save custom variables
thisExp.addData(“cat_average_correct”, test_corr_average) #average accuracy append
thisExp.addData(‘cat_average_rt’, test_rt_average) #average rt append
‘’’
What did you try to make it work?:
I have tried many fixes including adding the ‘no response’ variable, initially I had the numbers there but worried it thought I may be referring to a list.
What specifically went wrong when you tried that?:

this is my error:

run(
File “C:\Users\Eimea\Documents\cf2024_motionav_adult\adult_CF2024_motionav_lastrun.py”, line 3963, in run
test_rt_average = average(test_rts)
File “<array_function internals>”, line 200, in average
File “C:\Program Files\PsychoPy\lib\site-packages\numpy\lib\function_base.py”, line 509, in average
a = np.asanyarray(a)
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

Include pasted full error message if possible. “That didn’t work” is not enough information.

or terms don’t work like this.

You have to check if a == b or a == c:

I think you can also use
if cat_resp2.keys in ['a','l']:
Which would check if the variable cat_resp2.keys is a member of the list ['a','l']

1 Like