October 2019
Intermediate to advanced
366 pages
12h 4m
English
The variables in TensorFlow are represented as tensors that are arrays of any number of dimensions. There are three main types of tensors—tf.Variable, tf.constant, and tf.placeholder. Except for tf.Variable, all the other tensors are immutable.
To check the shape of a tensor, we will use the following code:
# constanta = tf.constant(1)print(a.shape)>> ()# array of five elementsb = tf.constant([1,2,3,4,5])print(b.shape)>> (5,)
The elements of a tensor are easily accessible, and the mechanisms are similar to those employed by Python:
a = tf.constant([1,2,3,4,5])first_three_elem = a[:3]fourth_elem = a[3]sess = tf.Session()print(sess.run(first_three_elem))>> array([1,2,3])print(sess.run(fourth_elem))>> 4
Read now
Unlock full access