Giter VIP home page Giter VIP logo

Comments (3)

jorvis avatar jorvis commented on July 18, 2024

Of course, asking for help is often the fastest way to find the answer on your own. This works:

selected = adata[:, adata.var_names.isin(['Tcea1',])]

# This is for a complete matrix
for g, gene in enumerate(selected.var_names):
    for c, cell in enumerate(selected.obs_names):
        print("{0}\t{1}\t{2}".format(cell, gene, selected.X[c]))

It seems like using "isin()" when you're only going after one gene is suboptimal though.

from anndata.

falexwolf avatar falexwolf commented on July 18, 2024

Hi Joshua!
When you select one row or column, the matrix will get flattened, as this is numpy's behavior and often very practical. See the following comment in the Notes section http://anndata.readthedocs.io/en/latest/anndata.AnnData.html

adata = AnnData(np.ones((2, 2)))
adata[:, 0].X == adata.X[:, 0]

So, if you're only going for single gene, then you get a 1d vector and not a matrix. Would you like to see this behavior different? Your trick with ['Tcea1', ] is definitely a very good workaround if you want something two-dimensional.

PS: You can also use 'Tcea1' == adata.var_names instead of using .isin(...) when you only have a single element.

from anndata.

flying-sheep avatar flying-sheep commented on July 18, 2024

Of course, asking for help is often the fastest way to find the answer on your own.

haha yeah, it’s called rubber duck debugging

When you select one row or column, the matrix will get flattened, as this is numpy's behavior and often very practical.

Oh, once upon a time I made sure that this doesn’t happen in AnnData, since AnnData is always a 2D structure (You should always have (at least one) named cell(s) and gene(s), never just a 1D vector of expression values without knowing what dimension it is along)

from anndata.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.