doc_content
stringlengths 1
386k
| doc_id
stringlengths 5
188
|
---|---|
tf.math.argmin View source on GitHub Returns the index with the smallest value across axes of a tensor. View aliases Main aliases
tf.argmin
tf.math.argmin(
input, axis=None, output_type=tf.dtypes.int64, name=None
)
Returns the smallest index in case of ties.
Args
input A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, complex64, int64, qint8, quint8, qint32, bfloat16, uint16, complex128, half, uint32, uint64.
axis A Tensor. Must be one of the following types: int32, int64. int32 or int64, must be in the range -rank(input), rank(input)). Describes which axis of the input Tensor to reduce across. For vectors, use axis = 0.
output_type An optional tf.DType from: tf.int32, tf.int64. Defaults to tf.int64.
name A name for the operation (optional).
Returns A Tensor of type output_type.
Usage: import tensorflow as tf
a = [1, 10, 26.9, 2.8, 166.32, 62.3]
b = tf.math.argmin(input = a)
c = tf.keras.backend.eval(b)
# c = 0
# here a[0] = 1 which is the smallest element of a across axis 0 | tensorflow.math.argmin |
tf.math.asin Computes the trignometric inverse sine of x element-wise. View aliases Main aliases
tf.asin Compat aliases for migration See Migration guide for more details. tf.compat.v1.asin, tf.compat.v1.math.asin
tf.math.asin(
x, name=None
)
The tf.math.asin operation returns the inverse of tf.math.sin, such that if y = tf.math.sin(x) then, x = tf.math.asin(y).
Note: The output of tf.math.asin will lie within the invertible range of sine, i.e [-pi/2, pi/2].
For example: # Note: [1.047, 0.785] ~= [(pi/3), (pi/4)]
x = tf.constant([1.047, 0.785])
y = tf.math.sin(x) # [0.8659266, 0.7068252]
tf.math.asin(y) # [1.047, 0.785] = x
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, int8, int16, int32, int64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.asin |
tf.math.asinh Computes inverse hyperbolic sine of x element-wise. View aliases Main aliases
tf.asinh Compat aliases for migration See Migration guide for more details. tf.compat.v1.asinh, tf.compat.v1.math.asinh
tf.math.asinh(
x, name=None
)
Given an input tensor, this function computes inverse hyperbolic sine for every element in the tensor. Both input and output has a range of [-inf, inf]. x = tf.constant([-float("inf"), -2, -0.5, 1, 1.2, 200, 10000, float("inf")])
tf.math.asinh(x) ==> [-inf -1.4436355 -0.4812118 0.8813736 1.0159732 5.991471 9.903487 inf]
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.asinh |
tf.math.atan Computes the trignometric inverse tangent of x element-wise. View aliases Main aliases
tf.atan Compat aliases for migration See Migration guide for more details. tf.compat.v1.atan, tf.compat.v1.math.atan
tf.math.atan(
x, name=None
)
The tf.math.atan operation returns the inverse of tf.math.tan, such that if y = tf.math.tan(x) then, x = tf.math.atan(y).
Note: The output of tf.math.atan will lie within the invertible range of tan, i.e (-pi/2, pi/2).
For example: # Note: [1.047, 0.785] ~= [(pi/3), (pi/4)]
x = tf.constant([1.047, 0.785])
y = tf.math.tan(x) # [1.731261, 0.99920404]
tf.math.atan(y) # [1.047, 0.785] = x
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, int8, int16, int32, int64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.atan |
tf.math.atan2 Computes arctangent of y/x element-wise, respecting signs of the arguments. View aliases Main aliases
tf.atan2 Compat aliases for migration See Migration guide for more details. tf.compat.v1.atan2, tf.compat.v1.math.atan2
tf.math.atan2(
y, x, name=None
)
This is the angle ( \theta \in [-\pi, \pi] ) such that [ x = r \cos(\theta) ] and [ y = r \sin(\theta) ] where (r = \sqrt(x^2 + y^2) ).
Args
y A Tensor. Must be one of the following types: bfloat16, half, float32, float64.
x A Tensor. Must have the same type as y.
name A name for the operation (optional).
Returns A Tensor. Has the same type as y. | tensorflow.math.atan2 |
tf.math.atanh Computes inverse hyperbolic tangent of x element-wise. View aliases Main aliases
tf.atanh Compat aliases for migration See Migration guide for more details. tf.compat.v1.atanh, tf.compat.v1.math.atanh
tf.math.atanh(
x, name=None
)
Given an input tensor, this function computes inverse hyperbolic tangent for every element in the tensor. Input range is [-1,1] and output range is [-inf, inf]. If input is -1, output will be -inf and if the input is 1, output will be inf. Values outside the range will have nan as output. x = tf.constant([-float("inf"), -1, -0.5, 1, 0, 0.5, 10, float("inf")])
tf.math.atanh(x) ==> [nan -inf -0.54930615 inf 0. 0.54930615 nan nan]
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.atanh |
tf.math.bessel_i0 View source on GitHub Computes the Bessel i0 function of x element-wise. View aliases Main aliases
tf.math.special.bessel_i0 Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.bessel_i0, tf.compat.v1.math.special.bessel_i0
tf.math.bessel_i0(
x, name=None
)
Modified Bessel function of order 0. It is preferable to use the numerically stabler function i0e(x) instead.
tf.math.special.bessel_i0([-1., -0.5, 0.5, 1.]).numpy()
array([1.26606588, 1.06348337, 1.06348337, 1.26606588], dtype=float32)
Args
x A Tensor or SparseTensor. Must be one of the following types: half, float32, float64.
name A name for the operation (optional).
Returns A Tensor or SparseTensor, respectively. Has the same type as x.
Scipy Compatibility Equivalent to scipy.special.i0 | tensorflow.math.bessel_i0 |
tf.math.bessel_i0e View source on GitHub Computes the Bessel i0e function of x element-wise. View aliases Main aliases
tf.math.special.bessel_i0e Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.bessel_i0e, tf.compat.v1.math.special.bessel_i0e
tf.math.bessel_i0e(
x, name=None
)
Modified Bessel function of order 0.
tf.math.special.bessel_i0e([-1., -0.5, 0.5, 1.]).numpy()
array([0.46575961, 0.64503527, 0.64503527, 0.46575961], dtype=float32)
Args
x A Tensor or SparseTensor. Must be one of the following types: half, float32, float64.
name A name for the operation (optional).
Returns A Tensor or SparseTensor, respectively. Has the same type as x. If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.bessel_i0e(x.values, ...), x.dense_shape)
Scipy Compatibility Equivalent to scipy.special.i0e | tensorflow.math.bessel_i0e |
tf.math.bessel_i1 View source on GitHub Computes the Bessel i1 function of x element-wise. View aliases Main aliases
tf.math.special.bessel_i1 Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.bessel_i1, tf.compat.v1.math.special.bessel_i1
tf.math.bessel_i1(
x, name=None
)
Modified Bessel function of order 1. It is preferable to use the numerically stabler function i1e(x) instead.
tf.math.special.bessel_i1([-1., -0.5, 0.5, 1.]).numpy()
array([-0.5651591 , -0.25789431, 0.25789431, 0.5651591 ], dtype=float32)
Args
x A Tensor or SparseTensor. Must be one of the following types: half, float32, float64.
name A name for the operation (optional).
Returns A Tensor or SparseTensor, respectively. Has the same type as x.
Scipy Compatibility Equivalent to scipy.special.i1 | tensorflow.math.bessel_i1 |
tf.math.bessel_i1e View source on GitHub Computes the Bessel i1e function of x element-wise. View aliases Main aliases
tf.math.special.bessel_i1e Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.bessel_i1e, tf.compat.v1.math.special.bessel_i1e
tf.math.bessel_i1e(
x, name=None
)
Modified Bessel function of order 1.
tf.math.special.bessel_i1e([-1., -0.5, 0.5, 1.]).numpy()
array([-0.20791042, -0.15642083, 0.15642083, 0.20791042], dtype=float32)
Args
x A Tensor or SparseTensor. Must be one of the following types: half, float32, float64.
name A name for the operation (optional).
Returns A Tensor or SparseTensor, respectively. Has the same type as x. If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.bessel_i1e(x.values, ...), x.dense_shape)
Scipy Compatibility Equivalent to scipy.special.i1e | tensorflow.math.bessel_i1e |
tf.math.betainc Compute the regularized incomplete beta integral \(I_x(a, b)\). View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.betainc, tf.compat.v1.math.betainc
tf.math.betainc(
a, b, x, name=None
)
The regularized incomplete beta integral is defined as: \(I_x(a, b) = \frac{B(x; a, b)}{B(a, b)}\) where \(B(x; a, b) = \int_0^x t^{a-1} (1 - t)^{b-1} dt\) is the incomplete beta function and \(B(a, b)\) is the complete beta function.
Args
a A Tensor. Must be one of the following types: float32, float64.
b A Tensor. Must have the same type as a.
x A Tensor. Must have the same type as a.
name A name for the operation (optional).
Returns A Tensor. Has the same type as a. | tensorflow.math.betainc |
tf.math.bincount View source on GitHub Counts the number of occurrences of each value in an integer array.
tf.math.bincount(
arr, weights=None, minlength=None, maxlength=None, dtype=tf.dtypes.int32,
name=None, axis=None, binary_output=False
)
If minlength and maxlength are not given, returns a vector with length tf.reduce_max(arr) + 1 if arr is non-empty, and length 0 otherwise. If weights are non-None, then index i of the output stores the sum of the value in weights at each index where the corresponding value in arr is i. values = tf.constant([1,1,2,3,2,4,4,5])
tf.math.bincount(values) #[0 2 2 1 2 1]
Vector length = Maximum element in vector values is 5. Adding 1, which is 6 will be the vector length. Each bin value in the output indicates number of occurrences of the particular index. Here, index 1 in output has a value 2. This indicates value 1 occurs two times in values. values = tf.constant([1,1,2,3,2,4,4,5])
weights = tf.constant([1,5,0,1,0,5,4,5])
tf.math.bincount(values, weights=weights) #[0 6 0 1 9 5]
Bin will be incremented by the corresponding weight instead of 1. Here, index 1 in output has a value 6. This is the summation of weights corresponding to the value in values. Bin-counting on a certain axis This example takes a 2 dimensional input and returns a Tensor with bincounting on each sample.
data = np.array([[1, 2, 3, 0], [0, 0, 1, 2]], dtype=np.int32)
tf.math.bincount(data, axis=-1)
<tf.Tensor: shape=(2, 4), dtype=int32, numpy=
array([[1, 1, 1, 1],
[2, 1, 1, 0]], dtype=int32)>
Bin-counting with binary_output This example gives binary output instead of counting the occurrence.
data = np.array([[1, 2, 3, 0], [0, 0, 1, 2]], dtype=np.int32)
tf.math.bincount(data, axis=-1, binary_output=True)
<tf.Tensor: shape=(2, 4), dtype=int32, numpy=
array([[1, 1, 1, 1],
[1, 1, 1, 0]], dtype=int32)>
Args
arr A Tensor, RaggedTensor, or SparseTensor whose values should be counted. These tensors must have a rank of 2 if axis=-1.
weights If non-None, must be the same shape as arr. For each value in arr, the bin will be incremented by the corresponding weight instead of 1.
minlength If given, ensures the output has length at least minlength, padding with zeros at the end if necessary.
maxlength If given, skips values in arr that are equal or greater than maxlength, ensuring that the output has length at most maxlength.
dtype If weights is None, determines the type of the output bins.
name A name scope for the associated operations (optional).
axis The axis to slice over. Axes at and below axis will be flattened before bin counting. Currently, only 0, and -1 are supported. If None, all axes will be flattened (identical to passing 0).
binary_output If True, this op will output 1 instead of the number of times a token appears (equivalent to one_hot + reduce_any instead of one_hot + reduce_add). Defaults to False.
Returns A vector with the same dtype as weights or the given dtype. The bin values.
Raises InvalidArgumentError if negative values are provided as an input. | tensorflow.math.bincount |
tf.math.ceil View source on GitHub Return the ceiling of the input, element-wise. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.ceil, tf.compat.v1.math.ceil
tf.math.ceil(
x, name=None
)
For example:
tf.math.ceil([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0])
<tf.Tensor: shape=(7,), dtype=float32,
numpy=array([-1., -1., -0., 1., 2., 2., 2.], dtype=float32)>
Args
x A tf.Tensor. Must be one of the following types: bfloat16, half, float32, float64. int32
name A name for the operation (optional).
Returns A tf.Tensor. Has the same type as x.
Numpy Compatibility Equivalent to np.ceil | tensorflow.math.ceil |
tf.math.confusion_matrix View source on GitHub Computes the confusion matrix from predictions and labels.
tf.math.confusion_matrix(
labels, predictions, num_classes=None, weights=None, dtype=tf.dtypes.int32,
name=None
)
The matrix columns represent the prediction labels and the rows represent the real labels. The confusion matrix is always a 2-D array of shape [n, n], where n is the number of valid labels for a given classification task. Both prediction and labels must be 1-D arrays of the same shape in order for this function to work. If num_classes is None, then num_classes will be set to one plus the maximum value in either predictions or labels. Class labels are expected to start at 0. For example, if num_classes is 3, then the possible labels would be [0, 1, 2]. If weights is not None, then each prediction contributes its corresponding weight to the total value of the confusion matrix cell. For example: tf.math.confusion_matrix([1, 2, 4], [2, 2, 4]) ==>
[[0 0 0 0 0]
[0 0 1 0 0]
[0 0 1 0 0]
[0 0 0 0 0]
[0 0 0 0 1]]
Note that the possible labels are assumed to be [0, 1, 2, 3, 4], resulting in a 5x5 confusion matrix.
Args
labels 1-D Tensor of real labels for the classification task.
predictions 1-D Tensor of predictions for a given classification.
num_classes The possible number of labels the classification task can have. If this value is not provided, it will be calculated using both predictions and labels array.
weights An optional Tensor whose shape matches predictions.
dtype Data type of the confusion matrix.
name Scope name.
Returns A Tensor of type dtype with shape [n, n] representing the confusion matrix, where n is the number of possible labels in the classification task.
Raises
ValueError If both predictions and labels are not 1-D vectors and have mismatched shapes, or if weights is not None and its shape doesn't match predictions. | tensorflow.math.confusion_matrix |
tf.math.conj View source on GitHub Returns the complex conjugate of a complex number. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.conj, tf.compat.v1.math.conj
tf.math.conj(
x, name=None
)
Given a tensor x of complex numbers, this operation returns a tensor of complex numbers that are the complex conjugate of each element in x. The complex numbers in x must be of the form \(a + bj\), where a is the real part and b is the imaginary part. The complex conjugate returned by this operation is of the form \(a - bj\). For example:
x = tf.constant([-2.25 + 4.75j, 3.25 + 5.75j])
tf.math.conj(x)
<tf.Tensor: shape=(2,), dtype=complex128,
numpy=array([-2.25-4.75j, 3.25-5.75j])>
If x is real, it is returned unchanged. For example:
x = tf.constant([-2.25, 3.25])
tf.math.conj(x)
<tf.Tensor: shape=(2,), dtype=float32,
numpy=array([-2.25, 3.25], dtype=float32)>
Args
x Tensor to conjugate. Must have numeric or variant type.
name A name for the operation (optional).
Returns A Tensor that is the conjugate of x (with the same type).
Raises
TypeError If x is not a numeric tensor. Numpy Compatibility Equivalent to numpy.conj. | tensorflow.math.conj |
tf.math.cos Computes cos of x element-wise. View aliases Main aliases
tf.cos Compat aliases for migration See Migration guide for more details. tf.compat.v1.cos, tf.compat.v1.math.cos
tf.math.cos(
x, name=None
)
Given an input tensor, this function computes cosine of every element in the tensor. Input range is (-inf, inf) and output range is [-1,1]. If input lies outside the boundary, nan is returned. x = tf.constant([-float("inf"), -9, -0.5, 1, 1.2, 200, 10000, float("inf")])
tf.math.cos(x) ==> [nan -0.91113025 0.87758255 0.5403023 0.36235774 0.48718765 -0.95215535 nan]
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.cos |
tf.math.cosh Computes hyperbolic cosine of x element-wise. View aliases Main aliases
tf.cosh Compat aliases for migration See Migration guide for more details. tf.compat.v1.cosh, tf.compat.v1.math.cosh
tf.math.cosh(
x, name=None
)
Given an input tensor, this function computes hyperbolic cosine of every element in the tensor. Input range is [-inf, inf] and output range is [1, inf]. x = tf.constant([-float("inf"), -9, -0.5, 1, 1.2, 2, 10, float("inf")])
tf.math.cosh(x) ==> [inf 4.0515420e+03 1.1276259e+00 1.5430807e+00 1.8106556e+00 3.7621956e+00 1.1013233e+04 inf]
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.cosh |
tf.math.count_nonzero View source on GitHub Computes number of nonzero elements across dimensions of a tensor.
tf.math.count_nonzero(
input, axis=None, keepdims=None, dtype=tf.dtypes.int64, name=None
)
Reduces input along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each entry in axis. If keepdims is true, the reduced dimensions are retained with length 1. If axis has no entries, all dimensions are reduced, and a tensor with a single element is returned.
Note: Floating point comparison to zero is done by exact floating point equality check. Small values are not rounded to zero for purposes of the nonzero check.
For example: x = tf.constant([[0, 1, 0], [1, 1, 0]])
tf.math.count_nonzero(x) # 3
tf.math.count_nonzero(x, 0) # [1, 2, 0]
tf.math.count_nonzero(x, 1) # [1, 2]
tf.math.count_nonzero(x, 1, keepdims=True) # [[1], [2]]
tf.math.count_nonzero(x, [0, 1]) # 3
Note: Strings are compared against zero-length empty string "". Any string with a size greater than zero is already considered as nonzero.
For example: x = tf.constant(["", "a", " ", "b", ""])
tf.math.count_nonzero(x) # 3, with "a", " ", and "b" as nonzero strings.
Args
input The tensor to reduce. Should be of numeric type, bool, or string.
axis The dimensions to reduce. If None (the default), reduces all dimensions. Must be in the range [-rank(input), rank(input)).
keepdims If true, retains reduced dimensions with length 1.
dtype The output dtype; defaults to tf.int64.
name A name for the operation (optional).
Returns The reduced tensor (number of nonzero values). | tensorflow.math.count_nonzero |
tf.math.cumprod View source on GitHub Compute the cumulative product of the tensor x along axis. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.cumprod, tf.compat.v1.math.cumprod
tf.math.cumprod(
x, axis=0, exclusive=False, reverse=False, name=None
)
By default, this op performs an inclusive cumprod, which means that the first element of the input is identical to the first element of the output: tf.math.cumprod([a, b, c]) # [a, a * b, a * b * c]
By setting the exclusive kwarg to True, an exclusive cumprod is performed instead: tf.math.cumprod([a, b, c], exclusive=True) # [1, a, a * b]
By setting the reverse kwarg to True, the cumprod is performed in the opposite direction: tf.math.cumprod([a, b, c], reverse=True) # [a * b * c, b * c, c]
This is more efficient than using separate tf.reverse ops. The reverse and exclusive kwargs can also be combined: tf.math.cumprod([a, b, c], exclusive=True, reverse=True) # [b * c, c, 1]
Args
x A Tensor. Must be one of the following types: float32, float64, int64, int32, uint8, uint16, int16, int8, complex64, complex128, qint8, quint8, qint32, half.
axis A Tensor of type int32 (default: 0). Must be in the range [-rank(x), rank(x)).
exclusive If True, perform exclusive cumprod.
reverse A bool (default: False).
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.cumprod |
tf.math.cumsum View source on GitHub Compute the cumulative sum of the tensor x along axis. View aliases Main aliases
tf.cumsum Compat aliases for migration See Migration guide for more details. tf.compat.v1.cumsum, tf.compat.v1.math.cumsum
tf.math.cumsum(
x, axis=0, exclusive=False, reverse=False, name=None
)
By default, this op performs an inclusive cumsum, which means that the first element of the input is identical to the first element of the output: For example:
# tf.cumsum([a, b, c]) # [a, a + b, a + b + c]
x = tf.constant([2, 4, 6, 8])
tf.cumsum(x)
<tf.Tensor: shape=(4,), dtype=int32,
numpy=array([ 2, 6, 12, 20], dtype=int32)>
# using varying `axis` values
y = tf.constant([[2, 4, 6, 8], [1,3,5,7]])
tf.cumsum(y, axis=0)
<tf.Tensor: shape=(2, 4), dtype=int32, numpy=
array([[ 2, 4, 6, 8],
[ 3, 7, 11, 15]], dtype=int32)>
tf.cumsum(y, axis=1)
<tf.Tensor: shape=(2, 4), dtype=int32, numpy=
array([[ 2, 6, 12, 20],
[ 1, 4, 9, 16]], dtype=int32)>
By setting the exclusive kwarg to True, an exclusive cumsum is performed instead:
# tf.cumsum([a, b, c], exclusive=True) => [0, a, a + b]
x = tf.constant([2, 4, 6, 8])
tf.cumsum(x, exclusive=True)
<tf.Tensor: shape=(4,), dtype=int32,
numpy=array([ 0, 2, 6, 12], dtype=int32)>
By setting the reverse kwarg to True, the cumsum is performed in the opposite direction:
# tf.cumsum([a, b, c], reverse=True) # [a + b + c, b + c, c]
x = tf.constant([2, 4, 6, 8])
tf.cumsum(x, reverse=True)
<tf.Tensor: shape=(4,), dtype=int32,
numpy=array([20, 18, 14, 8], dtype=int32)>
This is more efficient than using separate tf.reverse ops. The reverse and exclusive kwargs can also be combined:
# tf.cumsum([a, b, c], exclusive=True, reverse=True) # [b + c, c, 0]
x = tf.constant([2, 4, 6, 8])
tf.cumsum(x, exclusive=True, reverse=True)
<tf.Tensor: shape=(4,), dtype=int32,
numpy=array([18, 14, 8, 0], dtype=int32)>
Args
x A Tensor. Must be one of the following types: float32, float64, int64, int32, uint8, uint16, int16, int8, complex64, complex128, qint8, quint8, qint32, half.
axis A Tensor of type int32 (default: 0). Must be in the range [-rank(x), rank(x)).
exclusive If True, perform exclusive cumsum.
reverse A bool (default: False).
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.cumsum |
tf.math.cumulative_logsumexp View source on GitHub Compute the cumulative log-sum-exp of the tensor x along axis. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.cumulative_logsumexp
tf.math.cumulative_logsumexp(
x, axis=0, exclusive=False, reverse=False, name=None
)
By default, this op performs an inclusive cumulative log-sum-exp, which means that the first element of the input is identical to the first element of the output. This operation is significantly more numerically stable than the equivalent tensorflow operation tf.math.log(tf.math.cumsum(tf.math.exp(x))), although computes the same result given infinite numerical precision. However, note that in some cases, it may be less stable than tf.math.reduce_logsumexp for a given element, as it applies the "log-sum-exp trick" in a different way. More precisely, where tf.math.reduce_logsumexp uses the following trick: log(sum(exp(x))) == log(sum(exp(x - max(x)))) + max(x)
it cannot be directly used here as there is no fast way of applying it to each prefix x[:i]. Instead, this function implements a prefix scan using pairwise log-add-exp, which is a commutative and associative (up to floating point precision) operator: log_add_exp(x, y) = log(exp(x) + exp(y))
= log(1 + exp(min(x, y) - max(x, y))) + max(x, y)
However, reducing using the above operator leads to a different computation tree (logs are taken repeatedly instead of only at the end), and the maximum is only computed pairwise instead of over the entire prefix. In general, this leads to a different and slightly less precise computation.
Args
x A Tensor. Must be one of the following types: float16, float32, float64.
axis A Tensor of type int32 or int64 (default: 0). Must be in the range [-rank(x), rank(x)).
exclusive If True, perform exclusive cumulative log-sum-exp.
reverse If True, performs the cumulative log-sum-exp in the reverse direction.
name A name for the operation (optional).
Returns A Tensor. Has the same shape and type as x. | tensorflow.math.cumulative_logsumexp |
tf.math.digamma Computes Psi, the derivative of Lgamma (the log of the absolute value of View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.digamma, tf.compat.v1.math.digamma
tf.math.digamma(
x, name=None
)
Gamma(x)), element-wise.
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.digamma |
tf.math.divide View source on GitHub Computes Python style division of x by y. View aliases Main aliases
tf.divide Compat aliases for migration See Migration guide for more details. tf.compat.v1.divide, tf.compat.v1.math.divide
tf.math.divide(
x, y, name=None
)
For example:
x = tf.constant([16, 12, 11])
y = tf.constant([4, 6, 2])
tf.divide(x,y)
<tf.Tensor: shape=(3,), dtype=float64,
numpy=array([4. , 2. , 5.5])>
Args
x A Tensor
y A Tensor
name A name for the operation (optional).
Returns A Tensor with same shape as input | tensorflow.math.divide |
tf.math.divide_no_nan View source on GitHub Computes a safe divide which returns 0 if the y is zero. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.div_no_nan, tf.compat.v1.math.divide_no_nan
tf.math.divide_no_nan(
x, y, name=None
)
Args
x A Tensor. Must be one of the following types: float32, float64.
y A Tensor whose dtype is compatible with x.
name A name for the operation (optional).
Returns The element-wise value of the x divided by y. | tensorflow.math.divide_no_nan |
tf.math.equal View source on GitHub Returns the truth value of (x == y) element-wise. View aliases Main aliases
tf.equal Compat aliases for migration See Migration guide for more details. tf.compat.v1.equal, tf.compat.v1.math.equal
tf.math.equal(
x, y, name=None
)
Performs a broadcast with the arguments and then an element-wise equality comparison, returning a Tensor of boolean values. For example:
x = tf.constant([2, 4])
y = tf.constant(2)
tf.math.equal(x, y)
<tf.Tensor: shape=(2,), dtype=bool, numpy=array([ True, False])>
x = tf.constant([2, 4])
y = tf.constant([2, 4])
tf.math.equal(x, y)
<tf.Tensor: shape=(2,), dtype=bool, numpy=array([ True, True])>
Args
x A tf.Tensor or tf.sparse.SparseTensor or tf.IndexedSlices.
y A tf.Tensor or tf.sparse.SparseTensor or tf.IndexedSlices.
name A name for the operation (optional).
Returns A tf.Tensor of type bool with the same size as that of x or y.
Raises tf.errors.InvalidArgumentError: If shapes of arguments are incompatible | tensorflow.math.equal |
tf.math.erf Computes the Gauss error function of x element-wise. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.erf, tf.compat.v1.math.erf
tf.math.erf(
x, name=None
)
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.erf(x.values, ...), x.dense_shape) | tensorflow.math.erf |
tf.math.erfc Computes the complementary error function of x element-wise. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.erfc, tf.compat.v1.math.erfc
tf.math.erfc(
x, name=None
)
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.erfc |
tf.math.erfcinv Computes the inverse of complementary error function. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.erfcinv
tf.math.erfcinv(
x, name=None
)
Given x, compute the inverse complementary error function of x. This function is the inverse of tf.math.erfc, and is defined on [0, 2].
tf.math.erfcinv([0., 0.2, 1., 1.5, 2.])
<tf.Tensor: shape=(5,), dtype=float32, numpy=
array([ inf, 0.9061935, -0. , -0.4769363, -inf],
dtype=float32)>
Args
x Tensor with type float or double.
name A name for the operation (optional).
Returns Inverse complementary error function of x.
Numpy Compatibility Equivalent to scipy.special.erfcinv | tensorflow.math.erfcinv |
tf.math.erfinv Compute inverse error function. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.erfinv
tf.math.erfinv(
x, name=None
)
Given x, compute the inverse error function of x. This function is the inverse of tf.math.erf.
Args
x Tensor with type float or double.
name A name for the operation (optional).
Returns Inverse error function of x. | tensorflow.math.erfinv |
tf.math.exp View source on GitHub Computes exponential of x element-wise. \(y = e^x\). View aliases Main aliases
tf.exp Compat aliases for migration See Migration guide for more details. tf.compat.v1.exp, tf.compat.v1.math.exp
tf.math.exp(
x, name=None
)
This function computes the exponential of the input tensor element-wise. i.e. math.exp(x) or \(e^x\), where x is the input tensor. \(e\) denotes Euler's number and is approximately equal to 2.718281. Output is positive for any real input.
x = tf.constant(2.0)
tf.math.exp(x)
<tf.Tensor: shape=(), dtype=float32, numpy=7.389056>
x = tf.constant([2.0, 8.0])
tf.math.exp(x)
<tf.Tensor: shape=(2,), dtype=float32,
numpy=array([ 7.389056, 2980.958 ], dtype=float32)>
For complex numbers, the exponential value is calculated as $$ e^{x+iy} = {e^x} {e^{iy} } = {e^x} ({\cos (y) + i \sin (y)}) $$ For 1+1j the value would be computed as: $$ e^1 (\cos (1) + i \sin (1)) = 2.7182817 \times (0.5403023+0.84147096j) $$
x = tf.constant(1 + 1j)
tf.math.exp(x)
<tf.Tensor: shape=(), dtype=complex128,
numpy=(1.4686939399158851+2.2873552871788423j)>
Args
x A tf.Tensor. Must be one of the following types: bfloat16, half, float32, float64, complex64, complex128.
name A name for the operation (optional).
Returns A tf.Tensor. Has the same type as x.
Numpy Compatibility Equivalent to np.exp | tensorflow.math.exp |
tf.math.expm1 Computes exp(x) - 1 element-wise. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.expm1, tf.compat.v1.math.expm1
tf.math.expm1(
x, name=None
)
i.e. exp(x) - 1 or e^(x) - 1, where x is the input tensor. e denotes Euler's number and is approximately equal to 2.718281. x = tf.constant(2.0)
tf.math.expm1(x) ==> 6.389056
x = tf.constant([2.0, 8.0])
tf.math.expm1(x) ==> array([6.389056, 2979.958], dtype=float32)
x = tf.constant(1 + 1j)
tf.math.expm1(x) ==> (0.46869393991588515+2.2873552871788423j)
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.expm1 |
tf.math.floor View source on GitHub Returns element-wise largest integer not greater than x. View aliases Main aliases
tf.floor Compat aliases for migration See Migration guide for more details. tf.compat.v1.floor, tf.compat.v1.math.floor
tf.math.floor(
x, name=None
)
Both input range is (-inf, inf) and the ouput range consists of all integer values. For example:
x = tf.constant([1.3324, -1.5, 5.555, -2.532, 0.99, float("inf")])
tf.floor(x).numpy()
array([ 1., -2., 5., -3., 0., inf], dtype=float32)
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.floor |
tf.math.floordiv View source on GitHub Divides x / y elementwise, rounding toward the most negative integer. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.floordiv, tf.compat.v1.math.floordiv
tf.math.floordiv(
x, y, name=None
)
The same as tf.compat.v1.div(x,y) for integers, but uses tf.floor(tf.compat.v1.div(x,y)) for floating point arguments so that the result is always an integer (though possibly an integer represented as floating point). This op is generated by x // y floor division in Python 3 and in Python 2.7 with from __future__ import division. x and y must have the same type, and the result will have the same type as well.
Args
x Tensor numerator of real numeric type.
y Tensor denominator of real numeric type.
name A name for the operation (optional).
Returns x / y rounded down.
Raises
TypeError If the inputs are complex. | tensorflow.math.floordiv |
tf.math.floormod Returns element-wise remainder of division. When x < 0 xor y < 0 is View aliases Main aliases
tf.math.mod Compat aliases for migration See Migration guide for more details. tf.compat.v1.floormod, tf.compat.v1.math.floormod, tf.compat.v1.math.mod, tf.compat.v1.mod
tf.math.floormod(
x, y, name=None
)
true, this follows Python semantics in that the result here is consistent with a flooring divide. E.g. floor(x / y) * y + mod(x, y) = x.
Note: math.floormod supports broadcasting. More about broadcasting here
Args
x A Tensor. Must be one of the following types: int32, int64, uint64, bfloat16, half, float32, float64.
y A Tensor. Must have the same type as x.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.floormod |
tf.math.greater Returns the truth value of (x > y) element-wise. View aliases Main aliases
tf.greater Compat aliases for migration See Migration guide for more details. tf.compat.v1.greater, tf.compat.v1.math.greater
tf.math.greater(
x, y, name=None
)
Note: math.greater supports broadcasting. More about broadcasting here
Example: x = tf.constant([5, 4, 6])
y = tf.constant([5, 2, 5])
tf.math.greater(x, y) ==> [False, True, True]
x = tf.constant([5, 4, 6])
y = tf.constant([5])
tf.math.greater(x, y) ==> [False, False, True]
Args
x A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
y A Tensor. Must have the same type as x.
name A name for the operation (optional).
Returns A Tensor of type bool. | tensorflow.math.greater |
tf.math.greater_equal Returns the truth value of (x >= y) element-wise. View aliases Main aliases
tf.greater_equal Compat aliases for migration See Migration guide for more details. tf.compat.v1.greater_equal, tf.compat.v1.math.greater_equal
tf.math.greater_equal(
x, y, name=None
)
Note: math.greater_equal supports broadcasting. More about broadcasting here
Example: x = tf.constant([5, 4, 6, 7])
y = tf.constant([5, 2, 5, 10])
tf.math.greater_equal(x, y) ==> [True, True, True, False]
x = tf.constant([5, 4, 6, 7])
y = tf.constant([5])
tf.math.greater_equal(x, y) ==> [True, False, True, True]
Args
x A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
y A Tensor. Must have the same type as x.
name A name for the operation (optional).
Returns A Tensor of type bool. | tensorflow.math.greater_equal |
tf.math.igamma Compute the lower regularized incomplete Gamma function P(a, x). View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.igamma, tf.compat.v1.math.igamma
tf.math.igamma(
a, x, name=None
)
The lower regularized incomplete Gamma function is defined as: \(P(a, x) = gamma(a, x) / Gamma(a) = 1 - Q(a, x)\) where \(gamma(a, x) = \\int_{0}^{x} t^{a-1} exp(-t) dt\) is the lower incomplete Gamma function. Note, above Q(a, x) (Igammac) is the upper regularized complete Gamma function.
Args
a A Tensor. Must be one of the following types: float32, float64.
x A Tensor. Must have the same type as a.
name A name for the operation (optional).
Returns A Tensor. Has the same type as a. | tensorflow.math.igamma |
tf.math.igammac Compute the upper regularized incomplete Gamma function Q(a, x). View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.igammac, tf.compat.v1.math.igammac
tf.math.igammac(
a, x, name=None
)
The upper regularized incomplete Gamma function is defined as: \(Q(a, x) = Gamma(a, x) / Gamma(a) = 1 - P(a, x)\) where \(Gamma(a, x) = int_{x}^{\infty} t^{a-1} exp(-t) dt\) is the upper incomplete Gama function. Note, above P(a, x) (Igamma) is the lower regularized complete Gamma function.
Args
a A Tensor. Must be one of the following types: float32, float64.
x A Tensor. Must have the same type as a.
name A name for the operation (optional).
Returns A Tensor. Has the same type as a. | tensorflow.math.igammac |
tf.math.imag View source on GitHub Returns the imaginary part of a complex (or real) tensor. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.imag, tf.compat.v1.math.imag
tf.math.imag(
input, name=None
)
Given a tensor input, this operation returns a tensor of type float that is the imaginary part of each element in input considered as a complex number. If input is real, a tensor of all zeros is returned. For example: x = tf.constant([-2.25 + 4.75j, 3.25 + 5.75j])
tf.math.imag(x) # [4.75, 5.75]
Args
input A Tensor. Must be one of the following types: float, double, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor of type float32 or float64. | tensorflow.math.imag |
tf.math.invert_permutation Computes the inverse permutation of a tensor. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.invert_permutation, tf.compat.v1.math.invert_permutation
tf.math.invert_permutation(
x, name=None
)
This operation computes the inverse of an index permutation. It takes a 1-D integer tensor x, which represents the indices of a zero-based array, and swaps each value with its index position. In other words, for an output tensor y and an input tensor x, this operation computes the following: y[x[i]] = i for i in [0, 1, ..., len(x) - 1] The values must include 0. There can be no duplicate values or negative values. For example: # tensor `x` is [3, 4, 0, 2, 1]
invert_permutation(x) ==> [2, 4, 3, 0, 1]
Args
x A Tensor. Must be one of the following types: int32, int64. 1-D.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.invert_permutation |
tf.math.in_top_k View source on GitHub Says whether the targets are in the top K predictions. View aliases Main aliases
tf.nn.in_top_k
tf.math.in_top_k(
targets, predictions, k, name=None
)
This outputs a batch_size bool array, an entry out[i] is true if the prediction for the target class is finite (not inf, -inf, or nan) and among the top k predictions among all predictions for example i. Note that the behavior of InTopK differs from the TopK op in its handling of ties; if multiple classes have the same prediction value and straddle the top-k boundary, all of those classes are considered to be in the top k. More formally, let \(predictions_i\) be the predictions for all classes for example i, \(targets_i\) be the target class for example i, \(out_i\) be the output for example i, $$out_i = predictions_{i, targets_i} \in TopKIncludingTies(predictions_i)$$
Args
predictions A Tensor of type float32. A batch_size x classes tensor.
targets A Tensor. Must be one of the following types: int32, int64. A batch_size vector of class ids.
k An int. Number of top elements to look at for computing precision.
name A name for the operation (optional).
Returns A Tensor of type bool. Computed Precision at k as a bool Tensor. | tensorflow.math.in_top_k |
tf.math.is_finite Returns which elements of x are finite. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.debugging.is_finite, tf.compat.v1.is_finite, tf.compat.v1.math.is_finite
tf.math.is_finite(
x, name=None
)
Example: x = tf.constant([5.0, 4.8, 6.8, np.inf, np.nan])
tf.math.is_finite(x) ==> [True, True, True, False, False]
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64.
name A name for the operation (optional).
Returns A Tensor of type bool.
Numpy Compatibility Equivalent to np.isfinite | tensorflow.math.is_finite |
tf.math.is_inf Returns which elements of x are Inf. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.debugging.is_inf, tf.compat.v1.is_inf, tf.compat.v1.math.is_inf
tf.math.is_inf(
x, name=None
)
Example: x = tf.constant([5.0, np.inf, 6.8, np.inf])
tf.math.is_inf(x) ==> [False, True, False, True]
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64.
name A name for the operation (optional).
Returns A Tensor of type bool.
Numpy Compatibility Equivalent to np.isinf | tensorflow.math.is_inf |
tf.math.is_nan Returns which elements of x are NaN. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.debugging.is_nan, tf.compat.v1.is_nan, tf.compat.v1.math.is_nan
tf.math.is_nan(
x, name=None
)
Example: x = tf.constant([5.0, np.nan, 6.8, np.nan, np.inf])
tf.math.is_nan(x) ==> [False, True, False, True, False]
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64.
name A name for the operation (optional).
Returns A Tensor of type bool.
Numpy Compatibility Equivalent to np.isnan | tensorflow.math.is_nan |
tf.math.is_non_decreasing View source on GitHub Returns True if x is non-decreasing. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.debugging.is_non_decreasing, tf.compat.v1.is_non_decreasing, tf.compat.v1.math.is_non_decreasing
tf.math.is_non_decreasing(
x, name=None
)
Elements of x are compared in row-major order. The tensor [x[0],...] is non-decreasing if for every adjacent pair we have x[i] <= x[i+1]. If x has less than two elements, it is trivially non-decreasing. See also: is_strictly_increasing
x1 = tf.constant([1.0, 1.0, 3.0])
tf.math.is_non_decreasing(x1)
<tf.Tensor: shape=(), dtype=bool, numpy=True>
x2 = tf.constant([3.0, 1.0, 2.0])
tf.math.is_non_decreasing(x2)
<tf.Tensor: shape=(), dtype=bool, numpy=False>
Args
x Numeric Tensor.
name A name for this operation (optional). Defaults to "is_non_decreasing"
Returns Boolean Tensor, equal to True iff x is non-decreasing.
Raises
TypeError if x is not a numeric tensor. | tensorflow.math.is_non_decreasing |
tf.math.is_strictly_increasing View source on GitHub Returns True if x is strictly increasing. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.debugging.is_strictly_increasing, tf.compat.v1.is_strictly_increasing, tf.compat.v1.math.is_strictly_increasing
tf.math.is_strictly_increasing(
x, name=None
)
Elements of x are compared in row-major order. The tensor [x[0],...] is strictly increasing if for every adjacent pair we have x[i] < x[i+1]. If x has less than two elements, it is trivially strictly increasing. See also: is_non_decreasing
x1 = tf.constant([1.0, 2.0, 3.0])
tf.math.is_strictly_increasing(x1)
<tf.Tensor: shape=(), dtype=bool, numpy=True>
x2 = tf.constant([3.0, 1.0, 2.0])
tf.math.is_strictly_increasing(x2)
<tf.Tensor: shape=(), dtype=bool, numpy=False>
Args
x Numeric Tensor.
name A name for this operation (optional). Defaults to "is_strictly_increasing"
Returns Boolean Tensor, equal to True iff x is strictly increasing.
Raises
TypeError if x is not a numeric tensor. | tensorflow.math.is_strictly_increasing |
tf.math.l2_normalize View source on GitHub Normalizes along dimension axis using an L2 norm. View aliases Main aliases
tf.linalg.l2_normalize, tf.nn.l2_normalize
tf.math.l2_normalize(
x, axis=None, epsilon=1e-12, name=None
)
For a 1-D tensor with axis = 0, computes output = x / sqrt(max(sum(x**2), epsilon))
For x with more dimensions, independently normalizes each 1-D slice along dimension axis.
Args
x A Tensor.
axis Dimension along which to normalize. A scalar or a vector of integers.
epsilon A lower bound value for the norm. Will use sqrt(epsilon) as the divisor if norm < sqrt(epsilon).
name A name for this operation (optional).
Returns A Tensor with the same shape as x. | tensorflow.math.l2_normalize |
tf.math.lbeta View source on GitHub Computes \(ln(|Beta(x)|)\), reducing along the last dimension. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.lbeta, tf.compat.v1.math.lbeta
tf.math.lbeta(
x, name=None
)
Given one-dimensional $z = [z_1,...,z_K]$, we define $$Beta(z) = \frac{\prod_j \Gamma(z_j)}{\Gamma(\sum_j z_j)},$$ where $\Gamma$ is the gamma function. And for $n + 1$ dimensional $x$ with shape $[N_1, ..., N_n, K]$, we define $$lbeta(x)[i_1, ..., i_n] = \log{|Beta(x[i_1, ..., i_n, :])|}.$$ In other words, the last dimension is treated as the $z$ vector. Note that if $z = [u, v]$, then $$Beta(z) = \frac{\Gamma(u)\Gamma(v)}{\Gamma(u + v)} = \int_0^1 t^{u-1} (1 - t)^{v-1} \mathrm{d}t,$$ which defines the traditional bivariate beta function. If the last dimension is empty, we follow the convention that the sum over the empty set is zero, and the product is one.
Args
x A rank n + 1 Tensor, n >= 0 with type float, or double.
name A name for the operation (optional).
Returns The logarithm of \(|Beta(x)|\) reducing along the last dimension. | tensorflow.math.lbeta |
tf.math.less Returns the truth value of (x < y) element-wise. View aliases Main aliases
tf.less Compat aliases for migration See Migration guide for more details. tf.compat.v1.less, tf.compat.v1.math.less
tf.math.less(
x, y, name=None
)
Note: math.less supports broadcasting. More about broadcasting here
Example: x = tf.constant([5, 4, 6])
y = tf.constant([5])
tf.math.less(x, y) ==> [False, True, False]
x = tf.constant([5, 4, 6])
y = tf.constant([5, 6, 7])
tf.math.less(x, y) ==> [False, True, True]
Args
x A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
y A Tensor. Must have the same type as x.
name A name for the operation (optional).
Returns A Tensor of type bool. | tensorflow.math.less |
tf.math.less_equal Returns the truth value of (x <= y) element-wise. View aliases Main aliases
tf.less_equal Compat aliases for migration See Migration guide for more details. tf.compat.v1.less_equal, tf.compat.v1.math.less_equal
tf.math.less_equal(
x, y, name=None
)
Note: math.less_equal supports broadcasting. More about broadcasting here
Example: x = tf.constant([5, 4, 6])
y = tf.constant([5])
tf.math.less_equal(x, y) ==> [True, True, False]
x = tf.constant([5, 4, 6])
y = tf.constant([5, 6, 6])
tf.math.less_equal(x, y) ==> [True, True, True]
Args
x A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
y A Tensor. Must have the same type as x.
name A name for the operation (optional).
Returns A Tensor of type bool. | tensorflow.math.less_equal |
tf.math.lgamma Computes the log of the absolute value of Gamma(x) element-wise. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.lgamma, tf.compat.v1.math.lgamma
tf.math.lgamma(
x, name=None
)
For positive numbers, this function computes log((input - 1)!) for every element in the tensor. lgamma(5) = log((5-1)!) = log(4!) = log(24) = 3.1780539 Example: x = tf.constant([0, 0.5, 1, 4.5, -4, -5.6])
tf.math.lgamma(x) ==> [inf, 0.5723649, 0., 2.4537368, inf, -4.6477685]
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.lgamma |
tf.math.log Computes natural logarithm of x element-wise. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.log, tf.compat.v1.math.log
tf.math.log(
x, name=None
)
I.e., \(y = \log_e x\). Example: x = tf.constant([0, 0.5, 1, 5]) tf.math.log(x) See: https://en.wikipedia.org/wiki/Logarithm
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.log |
tf.math.log1p Computes natural logarithm of (1 + x) element-wise. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.log1p, tf.compat.v1.math.log1p
tf.math.log1p(
x, name=None
)
I.e., \(y = \log_e (1 + x)\). Example:
x = tf.constant([0, 0.5, 1, 5])
tf.math.log1p(x)
<tf.Tensor: shape=(4,), dtype=float32, numpy=array([0. , 0.4054651, 0.6931472, 1.7917595], dtype=float32)>
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.log1p |
tf.math.logical_and View source on GitHub Logical AND function. View aliases Main aliases
tf.logical_and Compat aliases for migration See Migration guide for more details. tf.compat.v1.logical_and, tf.compat.v1.math.logical_and
tf.math.logical_and(
x, y, name=None
)
The operation works for the following input types: Two single elements of type bool
One tf.Tensor of type bool and one single bool, where the result will be calculated by applying logical AND with the single element to each element in the larger Tensor. Two tf.Tensor objects of type bool of the same shape. In this case, the result will be the element-wise logical AND of the two input tensors. Usage:
a = tf.constant([True])
b = tf.constant([False])
tf.math.logical_and(a, b)
<tf.Tensor: shape=(1,), dtype=bool, numpy=array([False])>
c = tf.constant([True])
x = tf.constant([False, True, True, False])
tf.math.logical_and(c, x)
<tf.Tensor: shape=(4,), dtype=bool, numpy=array([False, True, True, False])>
y = tf.constant([False, False, True, True])
z = tf.constant([False, True, False, True])
tf.math.logical_and(y, z)
<tf.Tensor: shape=(4,), dtype=bool, numpy=array([False, False, False, True])>
Args
x A tf.Tensor type bool.
y A tf.Tensor of type bool.
name A name for the operation (optional).
Returns A tf.Tensor of type bool with the same size as that of x or y. | tensorflow.math.logical_and |
tf.math.logical_not Returns the truth value of NOT x element-wise. View aliases Main aliases
tf.logical_not Compat aliases for migration See Migration guide for more details. tf.compat.v1.logical_not, tf.compat.v1.math.logical_not
tf.math.logical_not(
x, name=None
)
Example:
tf.math.logical_not(tf.constant([True, False]))
<tf.Tensor: shape=(2,), dtype=bool, numpy=array([False, True])>
Args
x A Tensor of type bool. A Tensor of type bool.
name A name for the operation (optional).
Returns A Tensor of type bool. | tensorflow.math.logical_not |
tf.math.logical_or Returns the truth value of x OR y element-wise. View aliases Main aliases
tf.logical_or Compat aliases for migration See Migration guide for more details. tf.compat.v1.logical_or, tf.compat.v1.math.logical_or
tf.math.logical_or(
x, y, name=None
)
Note: math.logical_or supports broadcasting. More about broadcasting here
Args
x A Tensor of type bool.
y A Tensor of type bool.
name A name for the operation (optional).
Returns A Tensor of type bool. | tensorflow.math.logical_or |
tf.math.logical_xor View source on GitHub Logical XOR function. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.logical_xor, tf.compat.v1.math.logical_xor
tf.math.logical_xor(
x, y, name='LogicalXor'
)
x ^ y = (x | y) & ~(x & y) The operation works for the following input types: Two single elements of type bool
One tf.Tensor of type bool and one single bool, where the result will be calculated by applying logical XOR with the single element to each element in the larger Tensor. Two tf.Tensor objects of type bool of the same shape. In this case, the result will be the element-wise logical XOR of the two input tensors. Usage:
a = tf.constant([True])
b = tf.constant([False])
tf.math.logical_xor(a, b)
<tf.Tensor: shape=(1,), dtype=bool, numpy=array([ True])>
c = tf.constant([True])
x = tf.constant([False, True, True, False])
tf.math.logical_xor(c, x)
<tf.Tensor: shape=(4,), dtype=bool, numpy=array([ True, False, False, True])>
y = tf.constant([False, False, True, True])
z = tf.constant([False, True, False, True])
tf.math.logical_xor(y, z)
<tf.Tensor: shape=(4,), dtype=bool, numpy=array([False, True, True, False])>
Args
x A tf.Tensor type bool.
y A tf.Tensor of type bool.
name A name for the operation (optional).
Returns A tf.Tensor of type bool with the same size as that of x or y. | tensorflow.math.logical_xor |
tf.math.log_sigmoid View source on GitHub Computes log sigmoid of x element-wise. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.log_sigmoid, tf.compat.v1.math.log_sigmoid
tf.math.log_sigmoid(
x, name=None
)
Specifically, y = log(1 / (1 + exp(-x))). For numerical stability, we use y = -tf.nn.softplus(-x).
Args
x A Tensor with type float32 or float64.
name A name for the operation (optional).
Returns A Tensor with the same type as x.
Usage Example: If a positive number is large, then its log_sigmoid will approach to 0 since the formula will be y = log( <large_num> / (1 + <large_num>) ) which approximates to log (1) which is 0.
x = tf.constant([0.0, 1.0, 50.0, 100.0])
tf.math.log_sigmoid(x)
<tf.Tensor: shape=(4,), dtype=float32, numpy=
array([-6.9314718e-01, -3.1326169e-01, -1.9287499e-22, -0.0000000e+00],
dtype=float32)>
If a negative number is large, its log_sigmoid will approach to the number itself since the formula will be y = log( 1 / (1 + <large_num>) ) which is log (1) - log ( (1 + <large_num>) ) which approximates to - <large_num> that is the number itself.
x = tf.constant([-100.0, -50.0, -1.0, 0.0])
tf.math.log_sigmoid(x)
<tf.Tensor: shape=(4,), dtype=float32, numpy=
array([-100. , -50. , -1.3132616, -0.6931472],
dtype=float32)> | tensorflow.math.log_sigmoid |
tf.math.maximum Returns the max of x and y (i.e. x > y ? x : y) element-wise. View aliases Main aliases
tf.maximum Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.maximum, tf.compat.v1.maximum
tf.math.maximum(
x, y, name=None
)
Example:
x = tf.constant([0., 0., 0., 0.])
y = tf.constant([-2., 0., 2., 5.])
tf.math.maximum(x, y)
<tf.Tensor: shape=(4,), dtype=float32, numpy=array([0., 0., 2., 5.], dtype=float32)>
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, uint8, int16, int32, int64.
y A Tensor. Must have the same type as x.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.maximum |
tf.math.minimum Returns the min of x and y (i.e. x < y ? x : y) element-wise. View aliases Main aliases
tf.minimum Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.minimum, tf.compat.v1.minimum
tf.math.minimum(
x, y, name=None
)
Both inputs are number-type tensors (except complex). minimum expects that both tensors have the same dtype. Examples:
x = tf.constant([0., 0., 0., 0.])
y = tf.constant([-5., -2., 0., 3.])
tf.math.minimum(x, y)
<tf.Tensor: shape=(4,), dtype=float32, numpy=array([-5., -2., 0., 0.], dtype=float32)>
Note that minimum supports broadcast semantics.
x = tf.constant([-5., 0., 0., 0.])
y = tf.constant([-3.])
tf.math.minimum(x, y)
<tf.Tensor: shape=(4,), dtype=float32, numpy=array([-5., -3., -3., -3.], dtype=float32)>
If inputs are not tensors, they will be converted to tensors. See tf.convert_to_tensor.
x = tf.constant([-3.], dtype=tf.float32)
tf.math.minimum([-5], x)
<tf.Tensor: shape=(1,), dtype=float32, numpy=array([-5.], dtype=float32)>
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, uint8, int16, int32, int64.
y A Tensor. Must have the same type as x.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.minimum |
tf.math.multiply View source on GitHub Returns an element-wise x * y. View aliases Main aliases
tf.multiply Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.multiply, tf.compat.v1.multiply
tf.math.multiply(
x, y, name=None
)
For example:
x = tf.constant(([1, 2, 3, 4]))
tf.math.multiply(x, x)
<tf.Tensor: shape=(4,), dtype=..., numpy=array([ 1, 4, 9, 16], dtype=int32)>
Since tf.math.multiply will convert its arguments to Tensors, you can also pass in non-Tensor arguments:
tf.math.multiply(7,6)
<tf.Tensor: shape=(), dtype=int32, numpy=42>
If x.shape is not thes same as y.shape, they will be broadcast to a compatible shape. (More about broadcasting here.) For example:
x = tf.ones([1, 2]);
y = tf.ones([2, 1]);
x * y # Taking advantage of operator overriding
<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[1., 1.],
[1., 1.]], dtype=float32)>
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, uint8, int8, uint16, int16, int32, int64, complex64, complex128.
y A Tensor. Must have the same type as x.
name A name for the operation (optional).
Returns
A Tensor. Has the same type as x.
Raises InvalidArgumentError: When x and y have incomptatible shapes or types. | tensorflow.math.multiply |
tf.math.multiply_no_nan View source on GitHub Computes the product of x and y and returns 0 if the y is zero, even if x is NaN or infinite. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.multiply_no_nan
tf.math.multiply_no_nan(
x, y, name=None
)
Args
x A Tensor. Must be one of the following types: float32, float64.
y A Tensor whose dtype is compatible with x.
name A name for the operation (optional).
Returns The element-wise value of the x times y. | tensorflow.math.multiply_no_nan |
tf.math.ndtri Compute quantile of Standard Normal. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.ndtri
tf.math.ndtri(
x, name=None
)
Args
x Tensor with type float or double.
name A name for the operation (optional).
Returns Inverse error function of x. | tensorflow.math.ndtri |
tf.math.negative Computes numerical negative value element-wise. View aliases Main aliases
tf.negative Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.negative, tf.compat.v1.negative
tf.math.negative(
x, name=None
)
I.e., \(y = -x\).
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, int8, int16, int32, int64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.negative(x.values, ...), x.dense_shape) | tensorflow.math.negative |
tf.math.nextafter Returns the next representable value of x1 in the direction of x2, element-wise. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.nextafter
tf.math.nextafter(
x1, x2, name=None
)
This operation returns the same result as the C++ std::nextafter function. It can also return a subnormal number.
Args
x1 A Tensor. Must be one of the following types: float64, float32.
x2 A Tensor. Must have the same type as x1.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x1.
Cpp Compatibility Equivalent to C++ std::nextafter function. | tensorflow.math.nextafter |
tf.math.not_equal View source on GitHub Returns the truth value of (x != y) element-wise. View aliases Main aliases
tf.not_equal Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.not_equal, tf.compat.v1.not_equal
tf.math.not_equal(
x, y, name=None
)
Performs a broadcast with the arguments and then an element-wise inequality comparison, returning a Tensor of boolean values. For example:
x = tf.constant([2, 4])
y = tf.constant(2)
tf.math.not_equal(x, y)
<tf.Tensor: shape=(2,), dtype=bool, numpy=array([False, True])>
x = tf.constant([2, 4])
y = tf.constant([2, 4])
tf.math.not_equal(x, y)
<tf.Tensor: shape=(2,), dtype=bool, numpy=array([False, False])>
Args
x A tf.Tensor or tf.sparse.SparseTensor or tf.IndexedSlices.
y A tf.Tensor or tf.sparse.SparseTensor or tf.IndexedSlices.
name A name for the operation (optional).
Returns A tf.Tensor of type bool with the same size as that of x or y.
Raises tf.errors.InvalidArgumentError: If shapes of arguments are incompatible | tensorflow.math.not_equal |
tf.math.polygamma Compute the polygamma function \(\psi^{(n)}(x)\). View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.polygamma, tf.compat.v1.polygamma
tf.math.polygamma(
a, x, name=None
)
The polygamma function is defined as: \(\psi^{(a)}(x) = \frac{d^a}{dx^a} \psi(x)\) where \(\psi(x)\) is the digamma function. The polygamma function is defined only for non-negative integer orders \a\.
Args
a A Tensor. Must be one of the following types: float32, float64.
x A Tensor. Must have the same type as a.
name A name for the operation (optional).
Returns A Tensor. Has the same type as a. | tensorflow.math.polygamma |
tf.math.polyval View source on GitHub Computes the elementwise value of a polynomial. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.polyval
tf.math.polyval(
coeffs, x, name=None
)
If x is a tensor and coeffs is a list n + 1 tensors, this function returns the value of the n-th order polynomial p(x) = coeffs[n-1] + coeffs[n-2] * x + ... + coeffs[0] * x**(n-1) evaluated using Horner's method, i.e. `p(x) = coeffs[n-1] + x * (coeffs[n-2] + ... + x * (coeffs[1] + x * coeffs[0]))`
Usage Example:
coefficients = [1.0, 2.5, -4.2]
x = 5.0
y = tf.math.polyval(coefficients, x)
y
<tf.Tensor: shape=(), dtype=float32, numpy=33.3>
Usage Example:
tf.math.polyval([2, 1, 0], 3) # evaluates 2 * (3**2) + 1 * (3**1) + 0 * (3**0)
<tf.Tensor: shape=(), dtype=int32, numpy=21>
tf.math.polyval can also be used in polynomial regression. Taking advantage of this function can facilitate writing a polynomial equation as compared to explicitly writing it out, especially for higher degree polynomials.
x = tf.constant(3)
theta1 = tf.Variable(2)
theta2 = tf.Variable(1)
theta3 = tf.Variable(0)
tf.math.polyval([theta1, theta2, theta3], x)
<tf.Tensor: shape=(), dtype=int32, numpy=21>
Args
coeffs A list of Tensor representing the coefficients of the polynomial.
x A Tensor representing the variable of the polynomial.
name A name for the operation (optional).
Returns A tensor of the shape as the expression p(x) with usual broadcasting rules for element-wise addition and multiplication applied.
Numpy Compatibility Equivalent to numpy.polyval. | tensorflow.math.polyval |
tf.math.pow View source on GitHub Computes the power of one value to another. View aliases Main aliases
tf.pow Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.pow, tf.compat.v1.pow
tf.math.pow(
x, y, name=None
)
Given a tensor x and a tensor y, this operation computes \(x^y\) for corresponding elements in x and y. For example: x = tf.constant([[2, 2], [3, 3]])
y = tf.constant([[8, 16], [2, 3]])
tf.pow(x, y) # [[256, 65536], [9, 27]]
Args
x A Tensor of type float16, float32, float64, int32, int64, complex64, or complex128.
y A Tensor of type float16, float32, float64, int32, int64, complex64, or complex128.
name A name for the operation (optional).
Returns A Tensor. | tensorflow.math.pow |
tf.math.real View source on GitHub Returns the real part of a complex (or real) tensor. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.real, tf.compat.v1.real
tf.math.real(
input, name=None
)
Given a tensor input, this operation returns a tensor of type float that is the real part of each element in input considered as a complex number. For example: x = tf.constant([-2.25 + 4.75j, 3.25 + 5.75j])
tf.math.real(x) # [-2.25, 3.25]
If input is already real, it is returned unchanged.
Args
input A Tensor. Must have numeric type.
name A name for the operation (optional).
Returns A Tensor of type float32 or float64. | tensorflow.math.real |
tf.math.reciprocal Computes the reciprocal of x element-wise. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.reciprocal, tf.compat.v1.reciprocal
tf.math.reciprocal(
x, name=None
)
I.e., \(y = 1 / x\).
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, int8, int16, int32, int64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.reciprocal |
tf.math.reciprocal_no_nan View source on GitHub Performs a safe reciprocal operation, element wise. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.reciprocal_no_nan
tf.math.reciprocal_no_nan(
x, name=None
)
If a particular element is zero, the reciprocal for that element is also set to zero. For example: x = tf.constant([2.0, 0.5, 0, 1], dtype=tf.float32)
tf.math.reciprocal_no_nan(x) # [ 0.5, 2, 0.0, 1.0 ]
Args
x A Tensor of type float16, float32, float64 complex64 or complex128.
name A name for the operation (optional).
Returns A Tensor of same shape and type as x.
Raises
TypeError x must be of a valid dtype. | tensorflow.math.reciprocal_no_nan |
tf.math.reduce_all View source on GitHub Computes the "logical and" of elements across dimensions of a tensor. View aliases Main aliases
tf.reduce_all
tf.math.reduce_all(
input_tensor, axis=None, keepdims=False, name=None
)
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1. If axis is None, all dimensions are reduced, and a tensor with a single element is returned. For example: x = tf.constant([[True, True], [False, False]])
tf.reduce_all(x) # False
tf.reduce_all(x, 0) # [False, False]
tf.reduce_all(x, 1) # [True, False]
Args
input_tensor The boolean tensor to reduce.
axis The dimensions to reduce. If None (the default), reduces all dimensions. Must be in the range [-rank(input_tensor), rank(input_tensor)).
keepdims If true, retains reduced dimensions with length 1.
name A name for the operation (optional).
Returns The reduced tensor.
Numpy Compatibility Equivalent to np.all | tensorflow.math.reduce_all |
tf.math.reduce_any View source on GitHub Computes the "logical or" of elements across dimensions of a tensor. View aliases Main aliases
tf.reduce_any
tf.math.reduce_any(
input_tensor, axis=None, keepdims=False, name=None
)
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1. If axis is None, all dimensions are reduced, and a tensor with a single element is returned. For example: x = tf.constant([[True, True], [False, False]])
tf.reduce_any(x) # True
tf.reduce_any(x, 0) # [True, True]
tf.reduce_any(x, 1) # [True, False]
Args
input_tensor The boolean tensor to reduce.
axis The dimensions to reduce. If None (the default), reduces all dimensions. Must be in the range [-rank(input_tensor), rank(input_tensor)).
keepdims If true, retains reduced dimensions with length 1.
name A name for the operation (optional).
Returns The reduced tensor.
Numpy Compatibility Equivalent to np.any | tensorflow.math.reduce_any |
tf.math.reduce_euclidean_norm View source on GitHub Computes the Euclidean norm of elements across dimensions of a tensor. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.reduce_euclidean_norm
tf.math.reduce_euclidean_norm(
input_tensor, axis=None, keepdims=False, name=None
)
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1. If axis is None, all dimensions are reduced, and a tensor with a single element is returned. For example: x = tf.constant([[1, 2, 3], [1, 1, 1]]) # x.dtype is tf.int32
tf.math.reduce_euclidean_norm(x) # returns 4 as dtype is tf.int32
y = tf.constant([[1, 2, 3], [1, 1, 1]], dtype = tf.float32)
tf.math.reduce_euclidean_norm(y) # returns 4.1231055 which is sqrt(17)
tf.math.reduce_euclidean_norm(y, 0) # [sqrt(2), sqrt(5), sqrt(10)]
tf.math.reduce_euclidean_norm(y, 1) # [sqrt(14), sqrt(3)]
tf.math.reduce_euclidean_norm(y, 1, keepdims=True) # [[sqrt(14)], [sqrt(3)]]
tf.math.reduce_euclidean_norm(y, [0, 1]) # sqrt(17)
Args
input_tensor The tensor to reduce. Should have numeric type.
axis The dimensions to reduce. If None (the default), reduces all dimensions. Must be in the range [-rank(input_tensor), rank(input_tensor)).
keepdims If true, retains reduced dimensions with length 1.
name A name for the operation (optional).
Returns The reduced tensor, of the same dtype as the input_tensor. | tensorflow.math.reduce_euclidean_norm |
tf.math.reduce_logsumexp View source on GitHub Computes log(sum(exp(elements across dimensions of a tensor))). View aliases Main aliases
tf.reduce_logsumexp
tf.math.reduce_logsumexp(
input_tensor, axis=None, keepdims=False, name=None
)
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1. If axis has no entries, all dimensions are reduced, and a tensor with a single element is returned. This function is more numerically stable than log(sum(exp(input))). It avoids overflows caused by taking the exp of large inputs and underflows caused by taking the log of small inputs. For example: x = tf.constant([[0., 0., 0.], [0., 0., 0.]])
tf.reduce_logsumexp(x) # log(6)
tf.reduce_logsumexp(x, 0) # [log(2), log(2), log(2)]
tf.reduce_logsumexp(x, 1) # [log(3), log(3)]
tf.reduce_logsumexp(x, 1, keepdims=True) # [[log(3)], [log(3)]]
tf.reduce_logsumexp(x, [0, 1]) # log(6)
Args
input_tensor The tensor to reduce. Should have numeric type.
axis The dimensions to reduce. If None (the default), reduces all dimensions. Must be in the range [-rank(input_tensor), rank(input_tensor)).
keepdims If true, retains reduced dimensions with length 1.
name A name for the operation (optional).
Returns The reduced tensor. | tensorflow.math.reduce_logsumexp |
tf.math.reduce_max View source on GitHub Computes the maximum of elements across dimensions of a tensor. View aliases Main aliases
tf.reduce_max
tf.math.reduce_max(
input_tensor, axis=None, keepdims=False, name=None
)
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1. If axis is None, all dimensions are reduced, and a tensor with a single element is returned. Usage example:
x = tf.constant([5, 1, 2, 4])
print(tf.reduce_max(x))
tf.Tensor(5, shape=(), dtype=int32)
x = tf.constant([-5, -1, -2, -4])
print(tf.reduce_max(x))
tf.Tensor(-1, shape=(), dtype=int32)
x = tf.constant([4, float('nan')])
print(tf.reduce_max(x))
tf.Tensor(nan, shape=(), dtype=float32)
x = tf.constant([float('nan'), float('nan')])
print(tf.reduce_max(x))
tf.Tensor(nan, shape=(), dtype=float32)
x = tf.constant([float('-inf'), float('inf')])
print(tf.reduce_max(x))
tf.Tensor(inf, shape=(), dtype=float32)
See the numpy docs for np.amax and np.nanmax behavior.
Args
input_tensor The tensor to reduce. Should have real numeric type.
axis The dimensions to reduce. If None (the default), reduces all dimensions. Must be in the range [-rank(input_tensor), rank(input_tensor)).
keepdims If true, retains reduced dimensions with length 1.
name A name for the operation (optional).
Returns The reduced tensor. | tensorflow.math.reduce_max |
tf.math.reduce_mean View source on GitHub Computes the mean of elements across dimensions of a tensor. View aliases Main aliases
tf.reduce_mean
tf.math.reduce_mean(
input_tensor, axis=None, keepdims=False, name=None
)
Reduces input_tensor along the dimensions given in axis by computing the mean of elements across the dimensions in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1. If axis is None, all dimensions are reduced, and a tensor with a single element is returned. For example:
x = tf.constant([[1., 1.], [2., 2.]])
tf.reduce_mean(x)
<tf.Tensor: shape=(), dtype=float32, numpy=1.5>
tf.reduce_mean(x, 0)
<tf.Tensor: shape=(2,), dtype=float32, numpy=array([1.5, 1.5], dtype=float32)>
tf.reduce_mean(x, 1)
<tf.Tensor: shape=(2,), dtype=float32, numpy=array([1., 2.], dtype=float32)>
Args
input_tensor The tensor to reduce. Should have numeric type.
axis The dimensions to reduce. If None (the default), reduces all dimensions. Must be in the range [-rank(input_tensor), rank(input_tensor)).
keepdims If true, retains reduced dimensions with length 1.
name A name for the operation (optional).
Returns The reduced tensor.
Numpy Compatibility Equivalent to np.mean Please note that np.mean has a dtype parameter that could be used to specify the output type. By default this is dtype=float64. On the other hand, tf.reduce_mean has an aggressive type inference from input_tensor, for example:
x = tf.constant([1, 0, 1, 0])
tf.reduce_mean(x)
<tf.Tensor: shape=(), dtype=int32, numpy=0>
y = tf.constant([1., 0., 1., 0.])
tf.reduce_mean(y)
<tf.Tensor: shape=(), dtype=float32, numpy=0.5> | tensorflow.math.reduce_mean |
tf.math.reduce_min View source on GitHub Computes the minimum of elements across dimensions of a tensor. View aliases Main aliases
tf.reduce_min
tf.math.reduce_min(
input_tensor, axis=None, keepdims=False, name=None
)
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1. If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Args
input_tensor The tensor to reduce. Should have real numeric type.
axis The dimensions to reduce. If None (the default), reduces all dimensions. Must be in the range [-rank(input_tensor), rank(input_tensor)).
keepdims If true, retains reduced dimensions with length 1.
name A name for the operation (optional).
Returns The reduced tensor.
For example:
a = tf.constant([[1, 2], [3, 4]])
tf.reduce_min(a)
<tf.Tensor: shape=(), dtype=int32, numpy=1>
Numpy Compatibility Equivalent to np.min | tensorflow.math.reduce_min |
tf.math.reduce_prod View source on GitHub Computes the product of elements across dimensions of a tensor. View aliases Main aliases
tf.reduce_prod
tf.math.reduce_prod(
input_tensor, axis=None, keepdims=False, name=None
)
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each entry in axis. If keepdims is true, the reduced dimensions are retained with length 1. If axis is None, all dimensions are reduced, and a tensor with a single element is returned.
Args
input_tensor The tensor to reduce. Should have numeric type.
axis The dimensions to reduce. If None (the default), reduces all dimensions. Must be in the range [-rank(input_tensor), rank(input_tensor)).
keepdims If true, retains reduced dimensions with length 1.
name A name for the operation (optional).
Returns The reduced tensor.
Numpy Compatibility Equivalent to np.prod | tensorflow.math.reduce_prod |
tf.math.reduce_std View source on GitHub Computes the standard deviation of elements across dimensions of a tensor. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.reduce_std
tf.math.reduce_std(
input_tensor, axis=None, keepdims=False, name=None
)
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1. If axis is None, all dimensions are reduced, and a tensor with a single element is returned. For example:
x = tf.constant([[1., 2.], [3., 4.]])
tf.math.reduce_std(x)
<tf.Tensor: shape=(), dtype=float32, numpy=1.118034>
tf.math.reduce_std(x, 0)
<tf.Tensor: shape=(2,), dtype=float32, numpy=array([1., 1.], dtype=float32)>
tf.math.reduce_std(x, 1)
<tf.Tensor: shape=(2,), dtype=float32, numpy=array([0.5, 0.5], dtype=float32)>
Args
input_tensor The tensor to reduce. Should have real or complex type.
axis The dimensions to reduce. If None (the default), reduces all dimensions. Must be in the range [-rank(input_tensor), rank(input_tensor)).
keepdims If true, retains reduced dimensions with length 1.
name A name scope for the associated operations (optional).
Returns The reduced tensor, of the same dtype as the input_tensor. Note, for complex64 or complex128 input, the returned Tensor will be of type float32 or float64, respectively.
Numpy Compatibility Equivalent to np.std Please note np.std has a dtype parameter that could be used to specify the output type. By default this is dtype=float64. On the other hand, tf.math.reduce_std has aggressive type inference from input_tensor. | tensorflow.math.reduce_std |
tf.math.reduce_sum View source on GitHub Computes the sum of elements across dimensions of a tensor. View aliases Main aliases
tf.reduce_sum
tf.math.reduce_sum(
input_tensor, axis=None, keepdims=False, name=None
)
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1. If axis is None, all dimensions are reduced, and a tensor with a single element is returned. For example:
# x has a shape of (2, 3) (two rows and three columns):
x = tf.constant([[1, 1, 1], [1, 1, 1]])
x.numpy()
array([[1, 1, 1],
[1, 1, 1]], dtype=int32)
# sum all the elements
# 1 + 1 + 1 + 1 + 1+ 1 = 6
tf.reduce_sum(x).numpy()
6
# reduce along the first dimension
# the result is [1, 1, 1] + [1, 1, 1] = [2, 2, 2]
tf.reduce_sum(x, 0).numpy()
array([2, 2, 2], dtype=int32)
# reduce along the second dimension
# the result is [1, 1] + [1, 1] + [1, 1] = [3, 3]
tf.reduce_sum(x, 1).numpy()
array([3, 3], dtype=int32)
# keep the original dimensions
tf.reduce_sum(x, 1, keepdims=True).numpy()
array([[3],
[3]], dtype=int32)
# reduce along both dimensions
# the result is 1 + 1 + 1 + 1 + 1 + 1 = 6
# or, equivalently, reduce along rows, then reduce the resultant array
# [1, 1, 1] + [1, 1, 1] = [2, 2, 2]
# 2 + 2 + 2 = 6
tf.reduce_sum(x, [0, 1]).numpy()
6
Args
input_tensor The tensor to reduce. Should have numeric type.
axis The dimensions to reduce. If None (the default), reduces all dimensions. Must be in the range [-rank(input_tensor), rank(input_tensor)].
keepdims If true, retains reduced dimensions with length 1.
name A name for the operation (optional).
Returns The reduced tensor, of the same dtype as the input_tensor.
Numpy Compatibility Equivalent to np.sum apart the fact that numpy upcast uint8 and int32 to int64 while tensorflow returns the same dtype as the input. | tensorflow.math.reduce_sum |
tf.math.reduce_variance View source on GitHub Computes the variance of elements across dimensions of a tensor. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.reduce_variance
tf.math.reduce_variance(
input_tensor, axis=None, keepdims=False, name=None
)
Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each of the entries in axis, which must be unique. If keepdims is true, the reduced dimensions are retained with length 1. If axis is None, all dimensions are reduced, and a tensor with a single element is returned. For example:
x = tf.constant([[1., 2.], [3., 4.]])
tf.math.reduce_variance(x)
<tf.Tensor: shape=(), dtype=float32, numpy=1.25>
tf.math.reduce_variance(x, 0)
<tf.Tensor: shape=(2,), dtype=float32, numpy=array([1., 1.], ...)>
tf.math.reduce_variance(x, 1)
<tf.Tensor: shape=(2,), dtype=float32, numpy=array([0.25, 0.25], ...)>
Args
input_tensor The tensor to reduce. Should have real or complex type.
axis The dimensions to reduce. If None (the default), reduces all dimensions. Must be in the range [-rank(input_tensor), rank(input_tensor)).
keepdims If true, retains reduced dimensions with length 1.
name A name scope for the associated operations (optional).
Returns The reduced tensor, of the same dtype as the input_tensor. Note, for complex64 or complex128 input, the returned Tensor will be of type float32 or float64, respectively.
Numpy Compatibility Equivalent to np.var Please note np.var has a dtype parameter that could be used to specify the output type. By default this is dtype=float64. On the other hand, tf.math.reduce_variance has aggressive type inference from input_tensor. | tensorflow.math.reduce_variance |
tf.math.rint Returns element-wise integer closest to x. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.rint, tf.compat.v1.rint
tf.math.rint(
x, name=None
)
If the result is midway between two representable values, the even representable is chosen. For example: rint(-1.5) ==> -2.0
rint(0.5000001) ==> 1.0
rint([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]) ==> [-2., -2., -0., 0., 2., 2., 2.]
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.rint |
tf.math.round View source on GitHub Rounds the values of a tensor to the nearest integer, element-wise. View aliases Main aliases
tf.round Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.round, tf.compat.v1.round
tf.math.round(
x, name=None
)
Rounds half to even. Also known as bankers rounding. If you want to round according to the current system rounding mode use tf::cint. For example: x = tf.constant([0.9, 2.5, 2.3, 1.5, -4.5])
tf.round(x) # [ 1.0, 2.0, 2.0, 2.0, -4.0 ]
Args
x A Tensor of type float16, float32, float64, int32, or int64.
name A name for the operation (optional).
Returns A Tensor of same shape and type as x. | tensorflow.math.round |
tf.math.rsqrt View source on GitHub Computes reciprocal of square root of x element-wise. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.rsqrt, tf.compat.v1.rsqrt
tf.math.rsqrt(
x, name=None
)
For example:
x = tf.constant([2., 0., -2.])
tf.math.rsqrt(x)
<tf.Tensor: shape=(3,), dtype=float32,
numpy=array([0.707, inf, nan], dtype=float32)>
Args
x A tf.Tensor. Must be one of the following types: bfloat16, half, float32, float64.
name A name for the operation (optional).
Returns A tf.Tensor. Has the same type as x. | tensorflow.math.rsqrt |
tf.math.scalar_mul View source on GitHub Multiplies a scalar times a Tensor or IndexedSlices object. View aliases Main aliases
tf.scalar_mul
tf.math.scalar_mul(
scalar, x, name=None
)
Intended for use in gradient code which might deal with IndexedSlices objects, which are easy to multiply by a scalar but more expensive to multiply with arbitrary tensors.
Args
scalar A 0-D scalar Tensor. Must have known shape.
x A Tensor or IndexedSlices to be scaled.
name A name for the operation (optional).
Returns scalar * x of the same type (Tensor or IndexedSlices) as x.
Raises
ValueError if scalar is not a 0-D scalar. | tensorflow.math.scalar_mul |
tf.math.segment_max Computes the maximum along segments of a tensor. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.segment_max, tf.compat.v1.segment_max
tf.math.segment_max(
data, segment_ids, name=None
)
Read the section on segmentation for an explanation of segments. Computes a tensor such that \(output_i = \max_j(data_j)\) where max is over j such that segment_ids[j] == i. If the max is empty for a given segment ID i, output[i] = 0. For example: c = tf.constant([[1,2,3,4], [4, 3, 2, 1], [5,6,7,8]])
tf.segment_max(c, tf.constant([0, 0, 1]))
# ==> [[4, 3, 3, 4],
# [5, 6, 7, 8]]
Args
data A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
segment_ids A Tensor. Must be one of the following types: int32, int64. A 1-D tensor whose size is equal to the size of data's first dimension. Values should be sorted and can be repeated.
name A name for the operation (optional).
Returns A Tensor. Has the same type as data. | tensorflow.math.segment_max |
tf.math.segment_mean Computes the mean along segments of a tensor. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.segment_mean, tf.compat.v1.segment_mean
tf.math.segment_mean(
data, segment_ids, name=None
)
Read the section on segmentation for an explanation of segments. Computes a tensor such that \(output_i = \frac{\sum_j data_j}{N}\) where mean is over j such that segment_ids[j] == i and N is the total number of values summed. If the mean is empty for a given segment ID i, output[i] = 0. For example: c = tf.constant([[1.0,2,3,4], [4, 3, 2, 1], [5,6,7,8]])
tf.segment_mean(c, tf.constant([0, 0, 1]))
# ==> [[2.5, 2.5, 2.5, 2.5],
# [5, 6, 7, 8]]
Args
data A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, complex64, int64, qint8, quint8, qint32, bfloat16, uint16, complex128, half, uint32, uint64.
segment_ids A Tensor. Must be one of the following types: int32, int64. A 1-D tensor whose size is equal to the size of data's first dimension. Values should be sorted and can be repeated.
name A name for the operation (optional).
Returns A Tensor. Has the same type as data. | tensorflow.math.segment_mean |
tf.math.segment_min Computes the minimum along segments of a tensor. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.segment_min, tf.compat.v1.segment_min
tf.math.segment_min(
data, segment_ids, name=None
)
Read the section on segmentation for an explanation of segments. Computes a tensor such that \(output_i = \min_j(data_j)\) where min is over j such that segment_ids[j] == i. If the min is empty for a given segment ID i, output[i] = 0. For example: c = tf.constant([[1,2,3,4], [4, 3, 2, 1], [5,6,7,8]])
tf.segment_min(c, tf.constant([0, 0, 1]))
# ==> [[1, 2, 2, 1],
# [5, 6, 7, 8]]
Args
data A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
segment_ids A Tensor. Must be one of the following types: int32, int64. A 1-D tensor whose size is equal to the size of data's first dimension. Values should be sorted and can be repeated.
name A name for the operation (optional).
Returns A Tensor. Has the same type as data. | tensorflow.math.segment_min |
tf.math.segment_prod Computes the product along segments of a tensor. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.segment_prod, tf.compat.v1.segment_prod
tf.math.segment_prod(
data, segment_ids, name=None
)
Read the section on segmentation for an explanation of segments. Computes a tensor such that \(output_i = \prod_j data_j\) where the product is over j such that segment_ids[j] == i. If the product is empty for a given segment ID i, output[i] = 1. For example: c = tf.constant([[1,2,3,4], [4, 3, 2, 1], [5,6,7,8]])
tf.segment_prod(c, tf.constant([0, 0, 1]))
# ==> [[4, 6, 6, 4],
# [5, 6, 7, 8]]
Args
data A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, complex64, int64, qint8, quint8, qint32, bfloat16, uint16, complex128, half, uint32, uint64.
segment_ids A Tensor. Must be one of the following types: int32, int64. A 1-D tensor whose size is equal to the size of data's first dimension. Values should be sorted and can be repeated.
name A name for the operation (optional).
Returns A Tensor. Has the same type as data. | tensorflow.math.segment_prod |
tf.math.segment_sum Computes the sum along segments of a tensor. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.segment_sum, tf.compat.v1.segment_sum
tf.math.segment_sum(
data, segment_ids, name=None
)
Read the section on segmentation for an explanation of segments. Computes a tensor such that \(output_i = \sum_j data_j\) where sum is over j such that segment_ids[j] == i. If the sum is empty for a given segment ID i, output[i] = 0. For example: c = tf.constant([[1,2,3,4], [4, 3, 2, 1], [5,6,7,8]])
tf.segment_sum(c, tf.constant([0, 0, 1]))
# ==> [[5, 5, 5, 5],
# [5, 6, 7, 8]]
Args
data A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, complex64, int64, qint8, quint8, qint32, bfloat16, uint16, complex128, half, uint32, uint64.
segment_ids A Tensor. Must be one of the following types: int32, int64. A 1-D tensor whose size is equal to the size of data's first dimension. Values should be sorted and can be repeated.
name A name for the operation (optional).
Returns A Tensor. Has the same type as data. | tensorflow.math.segment_sum |
tf.math.sigmoid View source on GitHub Computes sigmoid of x element-wise. View aliases Main aliases
tf.nn.sigmoid, tf.sigmoid Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.sigmoid, tf.compat.v1.nn.sigmoid, tf.compat.v1.sigmoid
tf.math.sigmoid(
x, name=None
)
Formula for calculating $\mathrm{sigmoid}(x) = y = 1 / (1 + \exp(-x))$. For $x \in (-\infty, \infty)$, $\mathrm{sigmoid}(x) \in (0, 1)$. Example Usage: If a positive number is large, then its sigmoid will approach to 1 since the formula will be y = <large_num> / (1 + <large_num>)
x = tf.constant([0.0, 1.0, 50.0, 100.0])
tf.math.sigmoid(x)
<tf.Tensor: shape=(4,), dtype=float32,
numpy=array([0.5 , 0.7310586, 1. , 1. ], dtype=float32)>
If a negative number is large, its sigmoid will approach to 0 since the formula will be y = 1 / (1 + <large_num>)
x = tf.constant([-100.0, -50.0, -1.0, 0.0])
tf.math.sigmoid(x)
<tf.Tensor: shape=(4,), dtype=float32, numpy=
array([0.0000000e+00, 1.9287499e-22, 2.6894143e-01, 0.5],
dtype=float32)>
Args
x A Tensor with type float16, float32, float64, complex64, or complex128.
name A name for the operation (optional).
Returns A Tensor with the same type as x.
Usage Example:
x = tf.constant([-128.0, 0.0, 128.0], dtype=tf.float32)
tf.sigmoid(x)
<tf.Tensor: shape=(3,), dtype=float32,
numpy=array([0. , 0.5, 1. ], dtype=float32)>
Scipy Compatibility Equivalent to scipy.special.expit | tensorflow.math.sigmoid |
tf.math.sign View source on GitHub Returns an element-wise indication of the sign of a number. View aliases Main aliases
tf.sign Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.sign, tf.compat.v1.sign
tf.math.sign(
x, name=None
)
y = sign(x) = -1 if x < 0; 0 if x == 0; 1 if x > 0. For complex numbers, y = sign(x) = x / |x| if x != 0, otherwise y = 0. Example usage:
# real number
tf.math.sign([0., 2., -3.])
<tf.Tensor: shape=(3,), dtype=float32,
numpy=array([ 0., 1., -1.], dtype=float32)>
# complex number
tf.math.sign([1 + 1j, 0 + 0j])
<tf.Tensor: shape=(2,), dtype=complex128,
numpy=array([0.70710678+0.70710678j, 0. +0.j ])>
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, int32, int64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.sign(x.values, ...), x.dense_shape). If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.sign(x.values, ...), x.dense_shape) | tensorflow.math.sign |
tf.math.sin Computes sine of x element-wise. View aliases Main aliases
tf.sin Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.sin, tf.compat.v1.sin
tf.math.sin(
x, name=None
)
Given an input tensor, this function computes sine of every element in the tensor. Input range is (-inf, inf) and output range is [-1,1]. x = tf.constant([-float("inf"), -9, -0.5, 1, 1.2, 200, 10, float("inf")])
tf.math.sin(x) ==> [nan -0.4121185 -0.47942555 0.84147096 0.9320391 -0.87329733 -0.54402107 nan]
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.sin |
tf.math.sinh Computes hyperbolic sine of x element-wise. View aliases Main aliases
tf.sinh Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.sinh, tf.compat.v1.sinh
tf.math.sinh(
x, name=None
)
Given an input tensor, this function computes hyperbolic sine of every element in the tensor. Input range is [-inf,inf] and output range is [-inf,inf]. x = tf.constant([-float("inf"), -9, -0.5, 1, 1.2, 2, 10, float("inf")])
tf.math.sinh(x) ==> [-inf -4.0515420e+03 -5.2109528e-01 1.1752012e+00 1.5094614e+00 3.6268604e+00 1.1013232e+04 inf]
Args
x A Tensor. Must be one of the following types: bfloat16, half, float32, float64, complex64, complex128.
name A name for the operation (optional).
Returns A Tensor. Has the same type as x. | tensorflow.math.sinh |
tf.math.sobol_sample Generates points from the Sobol sequence. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.sobol_sample
tf.math.sobol_sample(
dim, num_results, skip=0, dtype=tf.dtypes.float32, name=None
)
Creates a Sobol sequence with num_results samples. Each sample has dimension dim. Skips the first skip samples.
Args
dim Positive scalar Tensor representing each sample's dimension.
num_results Positive scalar Tensor of dtype int32. The number of Sobol points to return in the output.
skip (Optional) Positive scalar Tensor of dtype int32. The number of initial points of the Sobol sequence to skip. Default value is 0.
dtype (Optional) The tf.Dtype of the sample. One of: tf.float32 or tf.float64. Defaults to tf.float32.
name (Optional) Python str name prefixed to ops created by this function.
Returns Tensor of samples from Sobol sequence with shape [num_results, dim]. | tensorflow.math.sobol_sample |
tf.math.softplus Computes softplus: log(exp(features) + 1). View aliases Main aliases
tf.nn.softplus Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.softplus, tf.compat.v1.nn.softplus
tf.math.softplus(
features, name=None
)
Args
features A Tensor. Must be one of the following types: half, bfloat16, float32, float64.
name A name for the operation (optional).
Returns A Tensor. Has the same type as features. | tensorflow.math.softplus |
Module: tf.math.special Public API for tf.math.special namespace. Functions bessel_i0(...): Computes the Bessel i0 function of x element-wise. bessel_i0e(...): Computes the Bessel i0e function of x element-wise. bessel_i1(...): Computes the Bessel i1 function of x element-wise. bessel_i1e(...): Computes the Bessel i1e function of x element-wise. bessel_j0(...): Computes the Bessel j0 function of x element-wise. bessel_j1(...): Computes the Bessel j1 function of x element-wise. bessel_k0(...): Computes the Bessel k0 function of x element-wise. bessel_k0e(...): Computes the Bessel k0e function of x element-wise. bessel_k1(...): Computes the Bessel k1 function of x element-wise. bessel_k1e(...): Computes the Bessel k1e function of x element-wise. bessel_y0(...): Computes the Bessel y0 function of x element-wise. bessel_y1(...): Computes the Bessel y1 function of x element-wise. dawsn(...): Computes Dawson's integral of x element-wise. expint(...): Computes the Exponential integral of x element-wise. fresnel_cos(...): Computes Fresnel's cosine integral of x element-wise. fresnel_sin(...): Computes Fresnel's sine integral of x element-wise. spence(...): Computes Spence's integral of x element-wise. | tensorflow.math.special |
tf.math.special.bessel_j0 Computes the Bessel j0 function of x element-wise. View aliases Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.special.bessel_j0
tf.math.special.bessel_j0(
x, name=None
)
Modified Bessel function of order 0.
tf.math.special.bessel_j0([0.5, 1., 2., 4.]).numpy()
array([ 0.93846981, 0.76519769, 0.22389078, -0.39714981], dtype=float32)
Args
x A Tensor or SparseTensor. Must be one of the following types: half, float32, float64.
name A name for the operation (optional).
Returns A Tensor or SparseTensor, respectively. Has the same type as x.
Scipy Compatibility Equivalent to scipy.special.j0 | tensorflow.math.special.bessel_j0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.