Let's say I have a N elements and I know how there are connected. That means there's a vector [c1, c2, ..., cn] where ci in [0...CC] CC- components count.
I want to get adjacency matrix from it.
Simple example input
[0, 0, 1, 2, 0, 1]
output
1 1 0 0 1 0
1 1 0 0 1 0
0 0 1 0 0 1
0 0 0 1 0 0
1 1 0 0 1 0
0 0 1 0 0 1
Is it possible to get it with linear algebra only plus some extra tensor operations from TF?
That can be done simply with a broadcasted comparison with itself:
import tensorflow as tf
input = [0, 0, 1, 2, 0, 1]
adjacency_matrix = tf.cast(tf.equal(tf.expand_dims(input, 1), input), tf.int32)
print(sess.run(adjacency_matrix))
Output:
[[1 1 0 0 1 0]
[1 1 0 0 1 0]
[0 0 1 0 0 1]
[0 0 0 1 0 0]
[1 1 0 0 1 0]
[0 0 1 0 0 1]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With