Manipulating Tensors

In [1]:
import tensorflow as tf
In [3]:
initMatrix = [
    [10,7],
    [3,4]
]
t = tf.constant(initMatrix)
t
Out [3]:
<tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[10,  7],
       [ 3,  4]], dtype=int32)>

Add To A Tensor

In [6]:
t2 = t + 10
t2
Out [6]:
<tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[20, 17],
       [13, 14]], dtype=int32)>
In [7]:
t
Out [7]:
<tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[10,  7],
       [ 3,  4]], dtype=int32)>
In [9]:
# multiply
t3 = t * 2
t3
Out [9]:
<tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[20, 14],
       [ 6,  8]], dtype=int32)>
In [10]:
t4 = t - 2
t4
Out [10]:
<tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[8, 5],
       [1, 2]], dtype=int32)>
In [12]:
t5 = tf.multiply(t, 3)
t5
Out [12]:
<tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[30, 21],
       [ 9, 12]], dtype=int32)>