I'm working on analyzing a .h5ad file, which has the file type AnnData.
I've created separate lists based on some clustering program, and named the lists according to their cluster number (i.e. x1, x2, x3, x4 ...)
Now, I would like to take the mean of all the separate rows in each list. Of course this could be easily done by making many loops, but I thought it would be interesting to try and do it in in a single loop.
The code to do this for a single list is as follows:
means1 = []
for q in range(0, len(x1.var)):
    means1.append(np.mean(x1.X[:, q2])
Now, I would like to be able to substitute means1 and x1 with variable numbers.
For means1 this can be solved by making it a dict and using a second for with range(0, number) as follows:
x = {}
for q1 in range(0, 20):
    for q2 in range(0, len(x1.var)):
        x['mean' + q1] = np.mean(x1.X[:,q2])
But because the variable that I use in x1 already exists, it is impossible to just use  string formatting like 'x' + q1, since a str doesn't have the attribute .X.
Is there any way to do this, or should I accept that it's impossible?
 
     
     
    