How to isolate individual gene expression values within a cluster?

After clustering the data using scanpy, is it possible to extract list of genes alongwith their expression values from within a cluster ? Basically, I want to see the expression of a particular gene among the different clusters.

I am not sure how the expression of a gene would be defined within a cluster ?

Thanks in advance.

If you’re looking to get the expression values you could subset the AnnData to the clusters of interest like:

adata[adata.obs["leiden"].isin(["clusters", "of", "interest"])]

But there are also plenty of ways to visualize this in scanpy. See this plotting tutorial for examples.

Thank you very much for your reply.

I was wondering if the following would be a good metric to define mean expression of a gene within that cluster ?

`

cs13_adata[:,i].X.mean(0).item() ## where cs13 is the adata sliced from the original one via one of the clusuter and i is a given gene

`

That would calculate the mean, yes.