Skip to content

Difference between ‘distances’ and ‘connectivities’ in adata.obsp #1984

@alexmascension

Description

@alexmascension

I am currently working with sc.pp.neighbours() and when obtaining the adata.obsp['distances'] and adata.obsp['connectivities'] matrices I see some differences that I would like to know why do they happen.

For instance, for the pbmc3k dataset, the results I get are:
object_triku.obsp['distances']
<2700x2700 sparse matrix of type '<class 'numpy.float64'>'
with 37800 stored elements in Compressed Sparse Row format>

and

object_triku.obsp['connectivities']
<2700x2700 sparse matrix of type '<class 'numpy.float64'>'
with 61672 stored elements in Compressed Sparse Row format>

Mainly, in distance matrix all elements are zero, except n_neighbors elements that are non zero. In connectivities matrices I see that the elements that are nonzero are in the same positions as the nonzero elements from the distance matrix, although sometimes they are more, sometimes they are fewer.

This is strange to me because there are cases where the elements in the distances are zero, but its connectivity value is 1.

From that point, my question is: which matrix should I value most to get the neighbour graph?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions