In [1]:
import tensorflow as tf
In [2]:
vec = tf.constant([7,7], name='vector')
In [3]:
mat = tf.constant([[7,7],[9,9]], name='matrix')
create tensors whose elements are of a specific value
In [4]:
shape_tensor = tf.zeros([2,3],tf.int32)
In [5]:
with tf.Session() as ses:
print ses.run(shape_tensor)
tensor of shape and type (unless type is specified) as the input_tensor but all elements are zeros
In [6]:
input_tensor_model = [[1,2],[3,4],[5,6]]
In [7]:
zeroslike_tensor = tf.zeros_like(input_tensor_model)
In [8]:
with tf.Session() as ses:
print ses.run(zeroslike_tensor)
tensor of shape and all elements are ones
In [9]:
shape_one_tensor = tf.ones([3,3],tf.int32)
In [10]:
with tf.Session() as ses:
print ses.run(shape_one_tensor)
tensor of shape and type (unless type is specified) as the input_tensor but all elements are ones.
In [12]:
input_tensor_model_ones = [[1,2],[3,4],[5,6]]
In [13]:
onelikes = tf.ones_like(input_tensor_model_ones)
In [14]:
with tf.Session() as ses:
print ses.run(onelikes)
create a tensor filled with a scalar value
In [15]:
tensor_scalar = tf.fill([3, 3], 8)
In [16]:
with tf.Session() as ses:
print ses.run(tensor_scalar)
creating constants that are sequences
In [19]:
tensor_lin = tf.linspace(50.0 ,55.0, 5 , name="linspace")
In [20]:
with tf.Session() as ses:
print ses.run(tensor_lin)
create a sequence of numbers that begins at start and extends by increments of delta up to but not including limit
In [23]:
tensor_range = tf.range(3 ,15 , 3)
In [24]:
with tf.Session() as ses:
print ses.run(tensor_range)
TensorFlow sequences are not iterable
In [26]:
for a in range(4):
print a
In [27]:
for b in tf.range(4):
print b
In [ ]: