Defining Operations in TensorFlow
Learn about the different operations in TensorFlow.
An operation in TensorFlow takes one or more inputs and produces one or more outputs. If we take a look at the TensorFlow API, we’ll see that TensorFlow has a massive collection of operations available. Here, we’ll take a look at a selected few of the myriad TensorFlow operations.
Comparison operations
Comparison operations are useful for comparing two tensors. The following code example includes a few useful comparison operations.
To understand the working of these operations, let’s consider two example tensors, x and y:
We have two tensors, x and y, in the code above, which we used to compare element-wise. First, we check if these are equal or not (line 9), then we check if x is less than y (line 13), and finally, if x is greater than or equal to y (line 17). We select elements from tensors x and y based on the corresponding elements of the boolean tensor condition. If the condition is True, it selects the element from x; otherwise, it selects the element from y (lines 20–23).
In the figure below, we show the symbols of the comparison operators:
Mathematical operations
TensorFlow allows us to perform math ...