# Plot a matrix as a single point in space

I have a dataset of drugs represented as a graph, each of which is described by three non-square matrices:

1. edge index (A), an 2xe matrix, where e are the bonds of the molecule, the first line indicates the node (atom) from which the edge (bond) starts, and the second one the node where the edge arrives;
2. node feature matrix (X), an nx9 matrix, where n are the atoms of the molecule and 9 are the features used to describe these (e.g. atomic number, charge, hybridization);
3. edge feature matrix (E), an 4xe matrix, where e are the bonds of the molecule and 4 are the features used to describe these (e.g. type of bond, geometry).

I would like to plot these data on a Cartesian space to see if clusters are created based on their activity label. I thought, if I can reduce each matrix to a single point in space for each graph I will have three x, y, z coordinates, and then it will be very easy to plot the points. Does this make sense in your opinion? How could I go about turning a matrix into a single point using python? Finally, I leave you with an example of the graph I would like to create Thank you all!

You have three matrices, $$A$$, $$X$$, $$E$$, and you want to map them to a point in a $$3D$$ Cartesian space. This means that each matrix should be mapped to a single number, $$A \to x$$, $$X \to y$$, $$E \to z$$, i. e. you need to design three functions $$f(A) : A \to x$$, $$g(X) : X \to y$$, $$h(E) : E \to z$$.

The main question is how to design the functions $$f(A)$$, $$g(X)$$, and $$h(E)$$, and there is no single recipe here.

The most naive way is to use some matrix invariant. As your matrices are rectangular, it can be $$\sqrt{\mathrm{det}(AA^T)}$$. However, this mapping lacks any physical sense, and it better had at least some.

I don't know how you arranged the bonds in $$A$$, and $$E$$, and the atoms in $$X$$ but if you just put the atoms and bond in random, then $$f$$ and $$h$$ should be invariant to the change in columns (e.g. must be a function of the sum of the columns), and $$g$$ should be invariant to the change in rows.

You may check, if the property that you want to model is linear in the number bonds. If it is, your $$f$$ and $$h$$ will be linear: $$f(A) = \sum\limits_{ij}f_{ij}a_{ij}$$, $$h(E) = \sum\limits_{ij}h_{ij}e_{ij}$$. Then use some further probing to determine the coefficients $$f_{ij}$$ and $$h_{ij}$$. If the dependence is non-linear, you can check, how it depends on the number of bonds, and add this dependence into $$f$$ and $$h$$, and do similar things with $$g$$ analyzing the dependence on the number of atoms.

The property you model may depend not only on the number of atoms and bonds but also on their arrangements. Then, their positions in the matrices are not random.

By doing such analysis, after designing the functions $$f(A) : A \to x$$, $$g(X) : X \to y$$, and $$h(E) : E \to z$$, you can plot the resulting $$3D$$-points, e.g. according to this tutorial: link.