Does this matrix function exist

observations = rows
variables = columns

Connected matrix:

[ 1 0 0 -1]
[ 1 1 0  0]
[ 1 0 1  0]
[ 0 0 1  1]

all variables are connected to all other variables (by some path)

A. 1st is connected to 4th
B. 1st is connected to 2nd
C. 1st is connected to 3th
D. 3rd is connected to 4th

by A. and D., 1st is connected to 4th

———————-

Non-connected matrix:

[ 1 0  4 0]
[ 0 6  0 7]
[ 0 -2 0 3]
[ 5 0 -2 0]

Variables 1 and 3 are connected (by observations 1 and 4)
Variables 2 and 4 are connected (by observations 2 and 3)

Can be separated into two matrices:

[1  4]
[5 -2]

[ 6 7]
[-2 3]

———————-

I would like a function that would return the connectedness of variables (columns)

For 1st matrix, function would return [ 1 1 1 1], all variables are connected.
For 2nd matrix, function would return [ 1 2 1 2], variables 1 and 3 are connected, variables 2 and 4 are connected .

Does this type of function exist?