- TensorFlow 2.0 Quick Start Guide
- Tony Holdroyd
- 87字
- 2021-06-24 16:02:05
Finding the squared difference between two tensors
Later in this book, we will need to find the square of the difference between two tensors. The method is as follows:
tf.math.squared.difference( x, y, name=None)
Take the following example:
x = [1,3,5,7,11]
y = 5
s = tf.math.squared_difference(x,y)
s
The output will be as follows:
<tf.Tensor: id=279, shape=(5,), dtype=int32, numpy=array([16, 4, 0, 4, 36], dtype=int32)>
Note that the Python variables, x and y, are cast into tensors and that y is then broadcast across x in this example. So, for example, the first calculation is (1-5)2 = 16.
推薦閱讀