- TensorFlow 2.0 Quick Start Guide
- Tony Holdroyd
- 88字
- 2021-06-24 16:02:04
Broadcasting
Element-wise tensor operations support broadcasting in the same way that NumPy arrays do. The simplest example is that of multiplying a tensor by a scalar:
t4 = t2*4
print(t4)
The output will be as follows:
tf.Tensor( [[[ 0. 4. 8.] [12. 16. 20.]] [[24. 28. 32.] [36. 40. 44.]]], shape=(2, 2, 3), dtype=float32)
In this example, the scalar multiplier 4 is—conceptually, at least—expanded into an array that can be multiplied element-wise with t2. There is a very detailed discussion of broadcasting at https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html.