The tensorflow.math
module provides support for many basic mathematical operations. The tf.reciprocal ()
[alias tf.math.reciprocal
] provides support for calculating the reciprocal input amount in Tensorflow. Expected to be input as complex numbers in the form , floating point numbers and integers. Input type — tensor, and if the input contains more than one element, the inverse element is calculated,
,
Syntax : tf.reciprocal (x, name = None) or tf.math.reciprocal (x, name = None)
Parameters :
x : A Tensor of type bfloat16, half, float32, float64, int32, int64, complex64 or complex128.
name (optional): The name for the operation.Return type : A Tensor with the same size and type as that of x.
Code # 1:
|
Output :
Input type: Tens or ("Const: 0", shape = (6,), dtype = float32) Input: [-0.5 -0.1 0. 0.1 0.5 2.] Return type: Tensor ("reciprocal: 0", shape = (6,) , dtype = float32) Output: [-2. -10. inf 10. 2. 0.5]
denotes that inverse values approach infinity when input approaching zero.
Code # 2: Rendering
|
Output:
Input: [0 . 0.52631579 1.05263158 1.57894737 2.10526316 2.63157895 3.15789474 3.68421053 4.21052632 4.73684211 5.26315789 5.78947368 6.31578947 6.84210526 7.36842105 7.89473684 8.42105263 8.94736842 9.47368421 10.] Output: [inf 1.9 0.95 0.475 0.38 0.63333333 0.31666667 0.27142857 0.21111111 0.19 0.2375 0.17272727 0.15833333 0.14615385 0.13571429 0.12666667 0.11176471 0.10555556 0.11875 0.1]