Please forgive me if my terminology isn't correct - I'm new to this!
I'm trying to isolate certain entries based on the value of the first element in each item in an array and perform some operations on certain columns. Here's an example of the type of data I'm working with:
[[1, 99, 400],
[1, 95, 200],
[2, 92, 100],
[1, 85, 500],
[2, 88, 300]]
I need to figure out the means of columns 2 and 3 using a for loop, if statement, and arithmetic, respectively, for each condition (reflected in column 1, where values are either 1 or 2).
I'm trying to split the above array into two separate arrays for each condition, and then taking the mean of those columns using numpy.mean.
Here's what I want the lists to look like:
cond1 = [[1, 99, 400], [1, 95, 200], [1, 85, 500]]
cond2 = [[2, 92, 100], [2, 88, 300]]
I'm stuck on how to separate these conditions into two new arrays based on the first element. Here's the furthest I've gotten after googling about slicing.. but I'm stuck!
for x in stim:
if stim_acc[0]==1.0:
np.where(stim_acc[0] = 1.0)
cond1 = [[s,a,rt] for s, a, rt in zip(stim, acc, mrt)]
print(cond1)
regarding stim, acc, and mrt:
I have a several column-long set of data from which I isolated the stimulus (now stim), accuracy (now acc), and mean reaction time (now mrt) entries into a new list (the first in this post). I did this like so:
stim = data[:,1]
acc = data[:,3]
mrt = data[:,4]
stim_acc = [[s, a, rt] for s, a, rt in zip(stim, acc, mrt)]
print(stim_acc)
I've preemptively named the new list stim_acc because i foresaw this turning into a list calculating the accuracy for each condition over a loop.
Thank you, any help is greatly appreciated.
.groupby()