TensorFlow is a machine learning library used to implement deep learning algorithms in Python, and is very popular for being the most generally used machine learning framework by researchers and industry experts.
‘Tensors’ are simply a representation of matrices (as in linear algebra) or multi-dimensional arrays of numbers. And the ‘Flow’ describes the operations on the tensors.
These operations happen in a data flow (computational) graph where the nodes are the operations and the edges represent the data.
When you think of tensors, let three things come to mind:
- Dimension: the order in dimension of a tensor e.g 1st order tensor is depicted as a vector and 3rd order tensor as a matrix.
- Shape: the number of rows and columns it has.
- Data type: the data type of the objects.
Here’s a simple example of computing values as a Tensor:
import tensorflow as tf
a = tf.constant([[2.0, 3.0], [1.0, 2.0]])
b = tf.constant([[1.0, 4.0], [2.0, 0.0]])
# tf.matmul performs matrix multiplication
c = tf.matmul(a, b)
print(c)
The above prints:
tf.Tensor(
[[8. 8.]
[5. 4.]], shape=(2, 2), dtype=float32)
Note the dimension, the shape, and the data type.
In TensorFlow, the data flow graph, which is the model, is first created (or described) with their corresponding tensors. After creation, the machine learning operations can then run on the entire graph all at once till end.
Finding The Circumference Of Any Circle Using TensorFlow
We’ll now go through a simple example where we’ll use TensorFlow to find the Circumference of any circle given the radius.
See the next post on how we tackle that: Finding The Circumference Of Any Circle Using TensorFlow