Matrix Operations using Tensors
In [2]:
import tensorflow as tf
A = tf.constant([[1, 2, 3, 4]])
B = tf.constant([[3],
[4],
[5],
[5]])
C = tf.multiply(A, B) # Equivalent to A*B, element wise product
tf.print(C)
[[3 6 9 12] [4 8 12 16] [5 10 15 20] [5 10 15 20]]
In [3]:
import tensorflow as tf
A = tf.constant([[1, 2, 3, 4]])
B = tf.constant([[3], [4], [5], [5]])
C = tf.matmul(A, B)
tf.print(C)
[[46]]
In [4]:
A = tf.constant([[2, 24],
[2, 26],
[2, 57]])
B = tf.constant([[1000],
[150]])
C = tf.matmul(A, B)
tf.print(C)
[[5600] [5900] [10550]]
In [9]:
A = tf.constant([1,2,3])
B = tf.constant([1,2,3])
C = tf.add(A, B) # Element wise addition.
tf.print(C)
[2 4 6]
In [10]:
x = tf.constant([[1, 2, 3], [4, 5, 6]])
tf.transpose(x)
<tf.Tensor: shape=(3, 2), dtype=int32, numpy=
array([[1, 4],
[2, 5],
[3, 6]])> In [ ]: