<jupyter_start><jupyter_text>Compute interaction matrix==========================This example shows how to compute the interaction matrix.The interaction matrix quantifies the number of edges that nodesbelonging to a given annotation shares with the other annotations. It'sa descriptive statistics of the spatial graph.<jupyter_code>import squidpy as sq

adata = sq.datasets.imc()
adata<jupyter_output><empty_output><jupyter_text>First, we need to compute a connectivity matrix from spatialcoordinates. We can use squidpy.gr.spatial\_neighbors for this purpose.<jupyter_code>sq.gr.spatial_neighbors(adata)<jupyter_output><empty_output><jupyter_text>We can compute the interaction matrix withsquidpy.gr.interaction\_matrix. Specify `normalized = True` if you wanta row-normalized matrix. Results can be visualized withsquidpy.pl.interaction\_matrix.<jupyter_code>sq.gr.interaction_matrix(adata, cluster_key="cell type")
sq.pl.interaction_matrix(adata, cluster_key="cell type")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09950248756218906, 'fraction_numerical': 0.0, 'mean_word_length': 8.063063063063064, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '241457', 'license': 'MIT', 'n_tokens_mistral': 304, 'n_tokens_neox': 289, 'n_words': 82, 'path': 'docs/source/auto_examples/graph/compute_interaction_matrix.ipynb', 'repo_name': 'softbear/squidpy_notebooks', 'size': '1005'}