What Are Tensors
Tensors are multilinear maps from vector spaces to the real numbers.
E.g.
Scalar: (f:R→R,f(e1)=c)
Vector: (f:Rn→R,f(ei)=vi)
Matrix: (f:Rn×Rm→R,f(ei,ej)=Aij)
Importing Tensorflow for the demo
import tensorflow as tf
Running an Interactive session
session = tf.InteractiveSession()
Tensors in Tensorflow
A. Scalar (f:R→R,f(e1)=c)
a = tf.constant(3)
b = tf.constant(4)
c = a + b
c.eval()
7
B. Vector (f::Rn→R,:f(ei)=vi)
v1 = tf.constant([[1., 2., 3.]])
v2 = tf.constant([[3., 4., 5.]])
v3 = tf.add(v1, v2)
v3.eval()
array([[ 4., 6., 8.]], dtype=float32)
C. Matrix (f::Rn×Rm→R,:f(ei,ej)=Aij)
A = tf.constant([[1.,2.,3.],[4.,5.,6.],[7.,8.,9.]])
B = tf.ones([3,3])
C = tf.fill([3,3], 10.)
D = tf.add(A,B)
E = tf.add(D,C)
E.eval()
array([[ 12., 13., 14.],
[ 15., 16., 17.],
[ 18., 19., 20.]], dtype=float32)
%pwd
'/home/cobalt'
Written on February 26, 2017