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.


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.


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.


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.


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.


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


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


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.


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.


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.


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>


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


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


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.


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.


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.


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.


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.


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.


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.


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.


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.


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.


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.


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.


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


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)


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.


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.


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].


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.


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.


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


tf.math.special.bessel_j1 Computes the Bessel j1 function of x element-wise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.special.bessel_j1
tf.math.special.bessel_j1(
    x, name=None
)
 Modified Bessel function of order 1.
tf.math.special.bessel_j1([0.5, 1., 2., 4.]).numpy()
array([ 0.24226846,  0.44005059,  0.57672481, -0.06604333], 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.j1


tf.math.special.bessel_k0 Computes the Bessel k0 function of x element-wise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.special.bessel_k0
tf.math.special.bessel_k0(
    x, name=None
)
 Modified Bessel function of order 0. It is preferable to use the numerically stabler function k0e(x) instead.
tf.math.special.bessel_k0([0.5, 1., 2., 4.]).numpy()
array([0.92441907, 0.42102444, 0.11389387, 0.01115968], 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.k0


tf.math.special.bessel_k0e Computes the Bessel k0e function of x element-wise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.special.bessel_k0e
tf.math.special.bessel_k0e(
    x, name=None
)
 Modified Bessel function of order 0.
tf.math.special.bessel_k0e([0.5, 1., 2., 4.]).numpy()
array([1.52410939, 1.14446308, 0.84156822, 0.60929767], 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.k0e


tf.math.special.bessel_k1 Computes the Bessel k1 function of x element-wise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.special.bessel_k1
tf.math.special.bessel_k1(
    x, name=None
)
 Modified Bessel function of order 1. It is preferable to use the numerically stabler function k1e(x) instead.
tf.math.special.bessel_k1([0.5, 1., 2., 4.]).numpy()
array([1.65644112, 0.60190723, 0.13986588, 0.0124835 ], 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.k1


tf.math.special.bessel_k1e Computes the Bessel k1e function of x element-wise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.special.bessel_k1e
tf.math.special.bessel_k1e(
    x, name=None
)
 Modified Bessel function of order 1.
tf.math.special.bessel_k1e([0.5, 1., 2., 4.]).numpy()
array([2.73100971, 1.63615349, 1.03347685, 0.68157595], 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.k1e


tf.math.special.bessel_y0 Computes the Bessel y0 function of x element-wise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.special.bessel_y0
tf.math.special.bessel_y0(
    x, name=None
)
 Modified Bessel function of order 0.
tf.math.special.bessel_y0([0.5, 1., 2., 4.]).numpy()
array([-0.44451873,  0.08825696,  0.51037567, -0.01694074], 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.y0


tf.math.special.bessel_y1 Computes the Bessel y1 function of x element-wise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.special.bessel_y1
tf.math.special.bessel_y1(
    x, name=None
)
 Modified Bessel function of order 1.
tf.math.special.bessel_y1([0.5, 1., 2., 4.]).numpy()
array([-1.47147239, -0.78121282, -0.10703243,  0.39792571], 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.y1


tf.math.special.dawsn Computes Dawson's integral of x element-wise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.special.dawsn
tf.math.special.dawsn(
    x, name=None
)
 Dawson's integral is defined as exp(-x**2) times the integral of exp(t**2) from 0 to x, with the domain of definition all real numbers. Dawson's function is odd. >>> tf.math.special.dawsn([-1., -0.5, 0.5, 1.]).numpy()
array([-0.5380795, -0.4244364, 0.4244364,  0.5380795], dtype=float32)
 This implementation is based off of the Cephes math library.

 Args
  x   A Tensor or SparseTensor. Must be one of the following types: 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.dawsn


tf.math.special.expint Computes the Exponential integral of x element-wise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.special.expint
tf.math.special.expint(
    x, name=None
)
 The Exponential integral is defined as the integral of exp(t) / t from -inf to x, with the domain of definition all positive real numbers.
tf.math.special.expint([1., 1.1, 2.1, 4.1]).numpy()
array([ 1.8951179,  2.1673784,  5.3332353, 21.048464], dtype=float32)
 This implementation is based off of the Cephes math library.

 Args
  x   A Tensor or SparseTensor. Must be one of the following types: 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.expi


tf.math.special.fresnel_cos Computes Fresnel's cosine integral of x element-wise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.special.fresnel_cos
tf.math.special.fresnel_cos(
    x, name=None
)
 The Fresnel cosine integral is defined as the integral of cos(t^2) from 0 to x, with the domain of definition all real numbers. The Fresnel cosine integral is odd. >>> tf.math.special.fresnel_cos([-1., -0.1, 0.1, 1.]).numpy()
array([-0.7798934 , -0.09999753,  0.09999753,  0.7798934 ], dtype=float32)
 This implementation is based off of the Cephes math library.

 Args
  x   A Tensor or SparseTensor. Must be one of the following types: 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.fresnel second output.


tf.math.special.fresnel_sin Computes Fresnel's sine integral of x element-wise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.special.fresnel_sin
tf.math.special.fresnel_sin(
    x, name=None
)
 The Fresnel sine integral is defined as the integral of sin(t^2) from 0 to x, with the domain of definition all real numbers.
tf.math.special.fresnel_sin([-1., -0.1, 0.1, 1.]).numpy()
array([-0.43825912, -0.00052359,  0.00052359,  0.43825912], dtype=float32)
 This implementation is based off of the Cephes math library.

 Args
  x   A Tensor or SparseTensor. Must be one of the following types: 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.fresnel first output.


tf.math.special.spence Computes Spence's integral of x element-wise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.special.spence
tf.math.special.spence(
    x, name=None
)
 Spence's integral is defined as the integral of log(t) / (1 - t) from 1 to x, with the domain of definition all non-negative real numbers.
tf.math.special.spence([0.5, 1., 2., 3.]).numpy()
array([ 0.58224034,  0.        , -0.82246685, -1.4367464], dtype=float32)
 This implementation is based off of the Cephes math library.

 Args
  x   A Tensor or SparseTensor. Must be one of the following types: 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.spence


tf.math.sqrt     View source on GitHub    Computes element-wise square root of the input tensor.  View aliases  Main aliases
tf.sqrt Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.sqrt, tf.compat.v1.sqrt
tf.math.sqrt(
    x, name=None
)

Note: This operation does not support integer types.

x = tf.constant([[4.0], [16.0]])
tf.sqrt(x)
<tf.Tensor: shape=(2, 1), dtype=float32, numpy=
  array([[2.],
         [4.]], dtype=float32)>
y = tf.constant([[-4.0], [16.0]])
tf.sqrt(y)
<tf.Tensor: shape=(2, 1), dtype=float32, numpy=
  array([[nan],
         [ 4.]], dtype=float32)>
z = tf.constant([[-1.0], [16.0]], dtype=tf.complex128)
tf.sqrt(z)
<tf.Tensor: shape=(2, 1), dtype=complex128, numpy=
  array([[0.0+1.j],
         [4.0+0.j]])>

Note: In order to support complex complex, please provide an input tensor of complex64 or complex128.

 Args
  x   A tf.Tensor of type bfloat16, half, float32, float64, complex64, complex128
  name   A name for the operation (optional).

 Returns   A tf.Tensor of same size, type and sparsity as x. If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.sqrt(x.values, ...), x.dense_shape)


tf.math.square   Computes square of x element-wise.  View aliases  Main aliases
tf.square Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.square, tf.compat.v1.square
tf.math.square(
    x, name=None
)
 I.e., \(y = x * x = x^2\).
tf.math.square([-2., 0., 3.])
<tf.Tensor: shape=(3,), dtype=float32, numpy=array([4., 0., 9.], dtype=float32)>

 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.square(x.values, ...), x.dense_shape)


tf.math.squared_difference Returns conj(x - y)(x - y) element-wise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.squared_difference, tf.compat.v1.squared_difference
tf.math.squared_difference(
    x, y, name=None
)

Note: math.squared_difference supports broadcasting. More about broadcasting here

 Args
  x   A Tensor. Must be one of the following types: bfloat16, half, float32, float64, 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.


tf.math.subtract     View source on GitHub    Returns x - y element-wise.  View aliases  Main aliases
tf.subtract Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.subtract, tf.compat.v1.subtract
tf.math.subtract(
    x, y, name=None
)

Note: Subtract supports broadcasting. More about broadcasting here

 Args
  x   A Tensor. Must be one of the following types: bfloat16, half, float32, float64, uint8, int8, uint16, int16, int32, int64, complex64, complex128, uint32.
  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.


tf.math.tan Computes tan of x element-wise.  View aliases  Main aliases
tf.tan Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.tan, tf.compat.v1.tan
tf.math.tan(
    x, name=None
)
 Given an input tensor, this function computes tangent of every element in the tensor. Input range is (-inf, inf) and output range is (-inf, inf). 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.tan(x) ==> [nan 0.45231566 -0.5463025 1.5574077 2.572152 -1.7925274 0.32097113 nan]

 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.


tf.math.tanh Computes hyperbolic tangent of x element-wise.  View aliases  Main aliases
tf.nn.tanh, tf.tanh Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.tanh, tf.compat.v1.nn.tanh, tf.compat.v1.tanh
tf.math.tanh(
    x, name=None
)
 Given an input tensor, this function computes hyperbolic tangent of every element in the tensor. Input range is [-inf, inf] and output range is [-1,1].
x = tf.constant([-float("inf"), -5, -0.5, 1, 1.2, 2, 3, float("inf")])
tf.math.tanh(x)
  <tf.Tensor: shape=(8,), dtype=float32, numpy=
  array([-1.        , -0.99990916, -0.46211717,  0.7615942 ,  0.8336547 ,
          0.9640276 ,  0.9950547 ,  1.        ], 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. If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.tanh(x.values, ...), x.dense_shape)


tf.math.top_k     View source on GitHub    Finds values and indices of the k largest entries for the last dimension.  View aliases  Main aliases
tf.nn.top_k Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.top_k, tf.compat.v1.nn.top_k
tf.math.top_k(
    input, k=1, sorted=True, name=None
)
 If the input is a vector (rank=1), finds the k largest entries in the vector and outputs their values and indices as vectors. Thus values[j] is the j-th largest entry in input, and its index is indices[j]. For matrices (resp. higher rank input), computes the top k entries in each row (resp. vector along the last dimension). Thus, values.shape = indices.shape = input.shape[:-1] + [k]
 If two elements are equal, the lower-index element appears first.

 Args
  input   1-D or higher Tensor with last dimension at least k.
  k   0-D int32 Tensor. Number of top elements to look for along the last dimension (along each row for matrices).
  sorted   If true the resulting k elements will be sorted by the values in descending order.
  name   Optional name for the operation.

 Returns
  values   The k largest elements along each last dimensional slice.
  indices   The indices of values within the last dimension of input.


tf.math.truediv     View source on GitHub    Divides x / y elementwise (using Python 3 division operator semantics).  View aliases  Main aliases
tf.truediv Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.truediv, tf.compat.v1.truediv
tf.math.truediv(
    x, y, name=None
)

Note: Prefer using the Tensor operator or tf.divide which obey Python division operator semantics.
 This function forces Python 3 division operator semantics where all integer arguments are cast to floating types first. This op is generated by normal x / y division in Python 3 and in Python 2.7 with from __future__ import division. If you want integer division that rounds down, use x // y or tf.math.floordiv. x and y must have the same numeric type. If the inputs are floating point, the output will have the same type. If the inputs are integral, the inputs are cast to float32 for int8 and int16 and float64 for int32 and int64 (matching the behavior of Numpy).

 Args
  x   Tensor numerator of numeric type.
  y   Tensor denominator of numeric type.
  name   A name for the operation (optional).

 Returns   x / y evaluated in floating point.

 Raises
  TypeError   If x and y have different dtypes.


tf.math.unsorted_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.unsorted_segment_max, tf.compat.v1.unsorted_segment_max
tf.math.unsorted_segment_max(
    data, segment_ids, num_segments, name=None
)
 Read the section on segmentation for an explanation of segments. This operator is similar to the unsorted segment sum operator found (here). Instead of computing the sum over segments, it computes the maximum such that: \(output_i = \max_{j...} data[j...]\) where max is over tuples j... such that segment_ids[j...] == i. If the maximum is empty for a given segment ID i, it outputs the smallest possible value for the specific numeric type, output[i] = numeric_limits<T>::lowest(). If the given segment ID i is negative, then the corresponding value is dropped, and will not be included in the result.    For example: c = tf.constant([[1,2,3,4], [5,6,7,8], [4,3,2,1]])
tf.unsorted_segment_max(c, tf.constant([0, 1, 0]), num_segments=2)
# ==> [[ 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 tensor whose shape is a prefix of data.shape.
  num_segments   A Tensor. Must be one of the following types: int32, int64.
  name   A name for the operation (optional).

 Returns   A Tensor. Has the same type as data.


tf.math.unsorted_segment_mean       View source on GitHub    Computes the mean along segments of a tensor.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.unsorted_segment_mean, tf.compat.v1.unsorted_segment_mean
tf.math.unsorted_segment_mean(
    data, segment_ids, num_segments, name=None
)
 Read the section on segmentation for an explanation of segments. This operator is similar to the tf.math.unsorted_segment_sum operator. Instead of computing the sum over segments, it computes the mean of all entries belonging to a segment such that: \(output_i = 1/N_i \sum_{j...} data[j...]\) where the sum is over tuples j... such that segment_ids[j...] == i with \N_i\ being the number of occurrences of id \i\. If there is no entry for a given segment ID i, it outputs 0. If the given segment ID i is negative, the value is dropped and will not be added to the sum of the segment.

 Args
  data   A Tensor with floating point or complex dtype.
  segment_ids   An integer tensor whose shape is a prefix of data.shape.
  num_segments   An integer scalar Tensor. The number of distinct segment IDs.
  name   A name for the operation (optional).

 Returns   A Tensor. Has same shape as data, except for the first segment_ids.rank dimensions, which are replaced with a single dimension which has size num_segments.


tf.math.unsorted_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.unsorted_segment_min, tf.compat.v1.unsorted_segment_min
tf.math.unsorted_segment_min(
    data, segment_ids, num_segments, name=None
)
 Read the section on segmentation for an explanation of segments. This operator is similar to the unsorted segment sum operator found (here). Instead of computing the sum over segments, it computes the minimum such that: \(output_i = \min_{j...} data_[j...]\) where min is over tuples j... such that segment_ids[j...] == i. If the minimum is empty for a given segment ID i, it outputs the largest possible value for the specific numeric type, output[i] = numeric_limits<T>::max(). For example: c = tf.constant([[1,2,3,4], [5,6,7,8], [4,3,2,1]])
tf.unsorted_segment_min(c, tf.constant([0, 1, 0]), num_segments=2)
# ==> [[ 1,  2, 2, 1],
#       [5,  6, 7, 8]]
 If the given segment ID i is negative, then the corresponding value is dropped, and will not be included in the result.

 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 tensor whose shape is a prefix of data.shape.
  num_segments   A Tensor. Must be one of the following types: int32, int64.
  name   A name for the operation (optional).

 Returns   A Tensor. Has the same type as data.


tf.math.unsorted_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.unsorted_segment_prod, tf.compat.v1.unsorted_segment_prod
tf.math.unsorted_segment_prod(
    data, segment_ids, num_segments, name=None
)
 Read the section on segmentation for an explanation of segments. This operator is similar to the unsorted segment sum operator found (here). Instead of computing the sum over segments, it computes the product of all entries belonging to a segment such that: \(output_i = \prod_{j...} data[j...]\) where the product is over tuples j... such that segment_ids[j...] == i. For example: c = tf.constant([[1,2,3,4], [5,6,7,8], [4,3,2,1]])
tf.unsorted_segment_prod(c, tf.constant([0, 1, 0]), num_segments=2)
# ==> [[ 4,  6, 6, 4],
#       [5,  6, 7, 8]]
 If there is no entry for a given segment ID i, it outputs 1. If the given segment ID i is negative, then the corresponding value is dropped, and will not be included in the result.

 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 tensor whose shape is a prefix of data.shape.
  num_segments   A Tensor. Must be one of the following types: int32, int64.
  name   A name for the operation (optional).

 Returns   A Tensor. Has the same type as data.


tf.math.unsorted_segment_sqrt_n       View source on GitHub    Computes the sum along segments of a tensor divided by the sqrt(N).  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.unsorted_segment_sqrt_n, tf.compat.v1.unsorted_segment_sqrt_n
tf.math.unsorted_segment_sqrt_n(
    data, segment_ids, num_segments, name=None
)
 Read the section on segmentation for an explanation of segments. This operator is similar to the tf.math.unsorted_segment_sum operator. Additionally to computing the sum over segments, it divides the results by sqrt(N). \(output_i = 1/sqrt(N_i) \sum_{j...} data[j...]\) where the sum is over tuples j... such that segment_ids[j...] == i with \N_i\ being the number of occurrences of id \i\. If there is no entry for a given segment ID i, it outputs 0. Note that this op only supports floating point and complex dtypes, due to tf.sqrt only supporting these types. If the given segment ID i is negative, the value is dropped and will not be added to the sum of the segment.

 Args
  data   A Tensor with floating point or complex dtype.
  segment_ids   An integer tensor whose shape is a prefix of data.shape.
  num_segments   An integer scalar Tensor. The number of distinct segment IDs.
  name   A name for the operation (optional).

 Returns   A Tensor. Has same shape as data, except for the first segment_ids.rank dimensions, which are replaced with a single dimension which has size num_segments.


tf.math.unsorted_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.unsorted_segment_sum, tf.compat.v1.unsorted_segment_sum
tf.math.unsorted_segment_sum(
    data, segment_ids, num_segments, name=None
)
 Read the section on segmentation for an explanation of segments. Computes a tensor such that \(output[i] = \sum_{j...} data[j...]\) where the sum is over tuples j... such that segment_ids[j...] == i. Unlike SegmentSum, segment_ids need not be sorted and need not cover all values in the full range of valid values. If the sum is empty for a given segment ID i, output[i] = 0. If the given segment ID i is negative, the value is dropped and will not be added to the sum of the segment. num_segments should equal the number of distinct segment IDs.    c = tf.constant([[1,2,3,4], [5,6,7,8], [4,3,2,1]])
tf.unsorted_segment_sum(c, tf.constant([0, 1, 0]), num_segments=2)
# ==> [[ 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 tensor whose shape is a prefix of data.shape.
  num_segments   A Tensor. Must be one of the following types: int32, int64.
  name   A name for the operation (optional).

 Returns   A Tensor. Has the same type as data.


tf.math.xdivy Returns 0 if x == 0, and x / y otherwise, elementwise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.xdivy
tf.math.xdivy(
    x, y, name=None
)

 Args
  x   A Tensor. Must be one of the following types: half, float32, float64, 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.


tf.math.xlog1py Compute x * log1p(y).  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.xlog1py
tf.math.xlog1py(
    x, y, name=None
)
 Given x and y, compute x * log1p(y). This function safely returns zero when x = 0, no matter what the value of y is. Example:
tf.math.xlog1py(0., 1.)
<tf.Tensor: shape=(), dtype=float32, numpy=0.>
tf.math.xlog1py(1., 1.)
<tf.Tensor: shape=(), dtype=float32, numpy=0.6931472>
tf.math.xlog1py(2., 2.)
<tf.Tensor: shape=(), dtype=float32, numpy=2.1972246>
tf.math.xlog1py(0., -1.)
<tf.Tensor: shape=(), dtype=float32, numpy=0.>

 Args
  x   A tf.Tensor of type bfloat16, half, float32, float64, complex64, complex128
  y   A tf.Tensor of type bfloat16, half, float32, float64, complex64, complex128
  name   A name for the operation (optional).

 Returns   x * log1p(y).
 Scipy Compatibility Equivalent to scipy.special.xlog1py


tf.math.xlogy Returns 0 if x == 0, and x * log(y) otherwise, elementwise.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.xlogy
tf.math.xlogy(
    x, y, name=None
)

 Args
  x   A Tensor. Must be one of the following types: half, float32, float64, 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.


tf.math.zero_fraction     View source on GitHub    Returns the fraction of zeros in value.  View aliases  Main aliases
tf.nn.zero_fraction Compat aliases for migration See Migration guide for more details. tf.compat.v1.math.zero_fraction, tf.compat.v1.nn.zero_fraction
tf.math.zero_fraction(
    value, name=None
)
 If value is empty, the result is nan. This is useful in summaries to measure and report sparsity. For example, z = tf.nn.relu(...)
summ = tf.compat.v1.summary.scalar('sparsity', tf.nn.zero_fraction(z))

 Args
  value   A tensor of numeric type.
  name   A name for the operation (optional).

 Returns   The fraction of zeros in value, with type float32.


tf.math.zeta   Compute the Hurwitz zeta function \(\zeta(x, q)\).  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.math.zeta, tf.compat.v1.zeta
tf.math.zeta(
    x, q, name=None
)
 The Hurwitz zeta function is defined as: \(\zeta(x, q) = \sum_{n=0}^{\infty} (q + n)^{-x}\)

 Args
  x   A Tensor. Must be one of the following types: float32, float64.
  q   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.


tf.meshgrid     View source on GitHub    Broadcasts parameters for evaluation on an N-D grid.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.meshgrid
tf.meshgrid(
    *args, **kwargs
)
 Given N one-dimensional coordinate arrays *args, returns a list outputs of N-D coordinate arrays for evaluating expressions on an N-D grid. Notes: meshgrid supports cartesian ('xy') and matrix ('ij') indexing conventions. When the indexing argument is set to 'xy' (the default), the broadcasting instructions for the first two dimensions are swapped. Examples: Calling X, Y = meshgrid(x, y) with the tensors x = [1, 2, 3]
y = [4, 5, 6]
X, Y = tf.meshgrid(x, y)
# X = [[1, 2, 3],
#      [1, 2, 3],
#      [1, 2, 3]]
# Y = [[4, 4, 4],
#      [5, 5, 5],
#      [6, 6, 6]]

 Args
  *args   Tensors with rank 1.
  **kwargs    indexing: Either 'xy' or 'ij' (optional, default: 'xy'). name: A name for the operation (optional).

 Returns
  outputs   A list of N Tensors with rank N.

 Raises
  TypeError   When no keyword arguments (kwargs) are passed.
  ValueError   When indexing keyword argument is not one of xy or ij.


Module: tf.mixed_precision Public API for tf.mixed_precision namespace. Modules experimental module: Public API for tf.mixed_precision.experimental namespace.


Module: tf.mixed_precision.experimental Public API for tf.mixed_precision.experimental namespace. Classes class DynamicLossScale: Loss scale that dynamically adjusts itself. class FixedLossScale: Loss scale with a fixed value. class LossScale: Base class for all TF1 loss scales.


tf.mixed_precision.experimental.DynamicLossScale Loss scale that dynamically adjusts itself. Inherits From: LossScale  View aliases  Main aliases
tf.train.experimental.DynamicLossScale Compat aliases for migration See Migration guide for more details. tf.compat.v1.mixed_precision.DynamicLossScale, tf.compat.v1.mixed_precision.experimental.DynamicLossScale, tf.compat.v1.train.experimental.DynamicLossScale
tf.mixed_precision.experimental.DynamicLossScale(
    initial_loss_scale=(2 ** 15), increment_period=2000, multiplier=2.0
)
 Warning: This class is deprecated and will be unexposed from the TF 2 namespace starting in TensorFlow 2.5. In TensorFlow 2.5, this class will only be accessible as tf.compat.v1.mixed_precision.DynamicLossScale. Additionally in 2.5, you will no longer be able to pass a DynamicLossScale to a tf.keras.mixed_precision.Policy. All the functionality in this class has been merged into tf.keras.mixed_precision.LossScaleOptimizer, so this class is no longer needed. Dynamic loss scaling works by adjusting the loss scale as training progresses. The goal is to keep the loss scale as high as possible without overflowing the gradients. As long as the gradients do not overflow, raising the loss scale never hurts. The algorithm starts by setting the loss scale to an initial value. Every N steps that the gradients are finite, the loss scale is increased by some factor. However, if a NaN or Inf gradient is found, the gradients for that step are not applied, and the loss scale is decreased by the factor. This process tends to keep the loss scale as high as possible without gradients overflowing.

 Args
  initial_loss_scale   A Python float. The loss scale to use at the beginning. It's better to start this at a very high number, because a loss scale that is too high gets lowered far more quickly than a loss scale that is too low gets raised. The default is 2 ** 15, which is approximately half the maximum float16 value.
  increment_period   Increases loss scale every increment_period consecutive steps that finite gradients are encountered. If a nonfinite gradient is encountered, the count is reset back to zero.
  multiplier   The multiplier to use when increasing or decreasing the loss scale.

 Attributes
  increment_period

  initial_loss_scale

  multiplier
   Methods from_config View source
@classmethod
from_config(
    config
)
 Creates the LossScale from its config. get_config View source
get_config()
 Returns the config of this loss scale. update View source
update(
    grads
)
 Updates loss scale based on if gradients are finite in current step. __call__ View source
__call__()
 Returns the current loss scale as a scalar float32 tensor.


tf.mixed_precision.experimental.FixedLossScale Loss scale with a fixed value. Inherits From: LossScale  View aliases  Main aliases
tf.train.experimental.FixedLossScale Compat aliases for migration See Migration guide for more details. tf.compat.v1.mixed_precision.FixedLossScale, tf.compat.v1.mixed_precision.experimental.FixedLossScale, tf.compat.v1.train.experimental.FixedLossScale
tf.mixed_precision.experimental.FixedLossScale(
    loss_scale_value
)
 Warning: This class is deprecated and will be unexposed from the TF 2 namespace starting in TensorFlow 2.5. In TensorFlow 2.5, this class will only be accessible as tf.compat.v1.mixed_precision.FixedLossScale. Additionally in 2.5, you will no longer be able to pass a FixedLossScale to a tf.keras.mixed_precision.Policy. All the functionality in this class has been merged into tf.keras.mixed_precision.LossScaleOptimizer, so this class is no longer needed. The loss scale is not updated for the lifetime of instances of this class. A given instance of this class always returns the same number when called.

 Args
  loss_scale_value   A Python float. Its ideal value varies depending on models to run. Choosing a too small loss_scale might affect model quality; a too big loss_scale might cause inf or nan. There is no single right loss_scale to apply. There is no harm choosing a relatively big number as long as no nan or inf is encountered in training.

 Raises
  ValueError   If loss_scale_value is less than 1.    Methods from_config View source
@classmethod
from_config(
    config
)
 Creates the LossScale from its config. get_config View source
get_config()
 Returns the config of this loss scale. update View source
update(
    grads
)
 Updates the value of the loss scale. The loss scale will be potentially updated, based on the value of grads. The tensor returned by calling this class is only updated when this function is evaluated. In eager mode, this directly updates the loss scale, so that calling __call__ will return the newly updated loss scale. In graph mode, this returns an op that, when evaluated, updates the loss scale. This function also returns a should_apply_gradients bool. If False, gradients should not be applied to the variables that step, as nonfinite gradients were found, and the loss scale has been be updated to reduce the chance of finding nonfinite gradients in the next step. Some loss scale classes will always return True, as they cannot adjust themselves in response to nonfinite gradients. When a DistributionStrategy is used, this function may only be called in a cross-replica context.

 Args
  grads   A nested structure of unscaled gradients, each which is the gradient of the loss with respect to a weight. The gradients should have already been divided by the loss scale being before passed to this function. 'None' gradients are accepted, and are ignored.

 Returns
  update_op   In eager mode, None. In graph mode, an op to update the loss scale.
  should_apply_gradients   Either a bool or a scalar boolean tensor. If False, the caller should skip applying grads to the variables this step.    __call__ View source
__call__()
 Returns the current loss scale as a scalar float32 tensor.


tf.mixed_precision.experimental.LossScale Base class for all TF1 loss scales.  View aliases  Main aliases
tf.train.experimental.LossScale Compat aliases for migration See Migration guide for more details. tf.compat.v1.mixed_precision.LossScale, tf.compat.v1.mixed_precision.experimental.LossScale, tf.compat.v1.train.experimental.LossScale
tf.mixed_precision.experimental.LossScale()
 Warning: This class is deprecated and will be unexposed from the TF 2 namespace starting in TensorFlow 2.5. In TensorFlow 2.5, this class will only be accessible as tf.compat.v1.mixed_precision.LossScale. Additionally in 2.5, you will no longer be able to pass a LossScale to a tf.keras.mixed_precision.Policy. All the functionality in this class has been merged into tf.keras.mixed_precision.LossScaleOptimizer, so this class is no longer needed. This is an abstract base class, so you cannot instantiate it directly. Instead, use one of its concrete subclasses:  tf.compat.v1.mixed_precision.DynamicLossScale tf.compat.v1.mixed_precision.FixedLossScale  Loss scaling is a process that multiplies the loss by a multiplier called the loss scale, and divides each gradient by the same multiplier. The pseudocode for this process is: loss = ...
loss *= loss_scale
grads = gradients(loss, vars)
grads /= loss_scale
 Mathematically, loss scaling has no effect, but can help avoid numerical underflow in intermediate gradients when float16 tensors are used for mixed precision training. By multiplying the loss, each intermediate gradient will have the same multiplier applied. Instances of this class represent a loss scale. Calling instances of this class returns the loss scale as a scalar float32 tensor, while method update() updates the loss scale depending on the values of the gradients. Optimizers use instances of this class to scale loss and gradients. In most functions that accept a LossScale, you can also pass an int (such as 8) to create a FixedLossScale or the string "dynamic" to create a dynamic loss scale. Methods from_config View source
@classmethod
from_config(
    config
)
 Creates the LossScale from its config. get_config View source
@abc.abstractmethod
get_config()
 Returns the config of this loss scale. update View source
@abc.abstractmethod
update(
    grads
)
 Updates the value of the loss scale. The loss scale will be potentially updated, based on the value of grads. The tensor returned by calling this class is only updated when this function is evaluated. In eager mode, this directly updates the loss scale, so that calling __call__ will return the newly updated loss scale. In graph mode, this returns an op that, when evaluated, updates the loss scale. This function also returns a should_apply_gradients bool. If False, gradients should not be applied to the variables that step, as nonfinite gradients were found, and the loss scale has been be updated to reduce the chance of finding nonfinite gradients in the next step. Some loss scale classes will always return True, as they cannot adjust themselves in response to nonfinite gradients. When a DistributionStrategy is used, this function may only be called in a cross-replica context.

 Args
  grads   A nested structure of unscaled gradients, each which is the gradient of the loss with respect to a weight. The gradients should have already been divided by the loss scale being before passed to this function. 'None' gradients are accepted, and are ignored.

 Returns
  update_op   In eager mode, None. In graph mode, an op to update the loss scale.
  should_apply_gradients   Either a bool or a scalar boolean tensor. If False, the caller should skip applying grads to the variables this step.    __call__ View source
@abc.abstractmethod
__call__()
 Returns the current loss scale as a scalar float32 tensor.


Module: tf.mlir Public API for tf.mlir namespace. Modules experimental module: Public API for tf.mlir.experimental namespace.


Module: tf.mlir.experimental Public API for tf.mlir.experimental namespace. Functions convert_function(...): Import a ConcreteFunction and convert it to a textual MLIR module. convert_graph_def(...): Import a GraphDef and convert it to a textual MLIR module.


tf.mlir.experimental.convert_function Import a ConcreteFunction and convert it to a textual MLIR module.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.mlir.experimental.convert_function
tf.mlir.experimental.convert_function(
    concrete_function, pass_pipeline='tf-standard-pipeline'
)
 This API is only intended for inspecting the internals of TensorFlow and the string returned is at the moment intended for debugging purposes. A tf.function can be imported and converted from TensorFlow to TensorFlow MLIR with this API by extracting its ConcreteFunction (eagerly-executing wrapper around a tf.Graph). For example:
@tf.function
def add(a, b):
  return a + b

concrete_function = add.get_concrete_function(
    tf.TensorSpec(None, tf.dtypes.float32),
    tf.TensorSpec(None, tf.dtypes.float32))
tf.mlir.experimental.convert_function(concrete_function)
'...module attributes {...} {...}'

 Args
  concrete_function   An object of type ConcreteFunction.
  pass_pipeline   A textual description of an MLIR Pass Pipeline to run on the module, see MLIR documentation for the textual pass pipeline syntax.

 Returns   A textual representation of the MLIR module corresponding to the ConcreteFunction.

 Raises
  InvalidArgumentError   if concrete_function is invalid or cannot be converted to MLIR.


tf.mlir.experimental.convert_graph_def Import a GraphDef and convert it to a textual MLIR module.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.mlir.experimental.convert_graph_def
tf.mlir.experimental.convert_graph_def(
    graph_def, pass_pipeline='tf-standard-pipeline'
)
 This API is only intended for inspecting the internals of TensorFlow and the string returned is at the moment intended for debugging purposes.

 Args
  graph_def   An object of type graph_pb2.GraphDef or a textual proto representation of a valid GraphDef.
  pass_pipeline   A textual description of an MLIR Pass Pipeline to run on the module, see MLIR documentation for the textual pass pipeline syntax.

 Returns   A textual representation of the MLIR module corresponding to the graphdef.

 Raises
  InvalidArgumentError   if graph_def is invalid or cannot be converted to MLIR.


tf.Module     View source on GitHub    Base neural network module class.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.Module
tf.Module(
    name=None
)
 A module is a named container for tf.Variables, other tf.Modules and functions which apply to user input. For example a dense layer in a neural network might be implemented as a tf.Module:
class Dense(tf.Module):
  def __init__(self, input_dim, output_size, name=None):
    super(Dense, self).__init__(name=name)
    self.w = tf.Variable(
      tf.random.normal([input_dim, output_size]), name='w')
    self.b = tf.Variable(tf.zeros([output_size]), name='b')
  def __call__(self, x):
    y = tf.matmul(x, self.w) + self.b
    return tf.nn.relu(y)
 You can use the Dense layer as you would expect:
d = Dense(input_dim=3, output_size=2)
d(tf.ones([1, 3]))
<tf.Tensor: shape=(1, 2), dtype=float32, numpy=..., dtype=float32)>
 By subclassing tf.Module instead of object any tf.Variable or tf.Module instances assigned to object properties can be collected using the variables, trainable_variables or submodules property:
d.variables
    (<tf.Variable 'b:0' shape=(2,) dtype=float32, numpy=...,
    dtype=float32)>,
    <tf.Variable 'w:0' shape=(3, 2) dtype=float32, numpy=..., dtype=float32)>)
 Subclasses of tf.Module can also take advantage of the _flatten method which can be used to implement tracking of any other types. All tf.Module classes have an associated tf.name_scope which can be used to group operations in TensorBoard and create hierarchies for variable names which can help with debugging. We suggest using the name scope when creating nested submodules/parameters or for forward methods whose graph you might want to inspect in TensorBoard. You can enter the name scope explicitly using with self.name_scope: or you can annotate methods (apart from __init__) with @tf.Module.with_name_scope.
class MLP(tf.Module):
  def __init__(self, input_size, sizes, name=None):
    super(MLP, self).__init__(name=name)
    self.layers = []
    with self.name_scope:
      for size in sizes:
        self.layers.append(Dense(input_dim=input_size, output_size=size))
        input_size = size
  @tf.Module.with_name_scope
  def __call__(self, x):
    for layer in self.layers:
      x = layer(x)
    return x

module = MLP(input_size=5, sizes=[5, 5])
module.variables
(<tf.Variable 'mlp/b:0' shape=(5,) dtype=float32, numpy=..., dtype=float32)>,
<tf.Variable 'mlp/w:0' shape=(5, 5) dtype=float32, numpy=...,
   dtype=float32)>,
<tf.Variable 'mlp/b:0' shape=(5,) dtype=float32, numpy=..., dtype=float32)>,
<tf.Variable 'mlp/w:0' shape=(5, 5) dtype=float32, numpy=...,
   dtype=float32)>)

 Attributes
  name   Returns the name of this module as passed or determined in the ctor.
Note: This is not the same as the self.name_scope.name which includes parent module names.

  name_scope   Returns a tf.name_scope instance for this class.
  submodules   Sequence of all sub-modules. Submodules are modules which are properties of this module, or found as properties of modules which are properties of this module (and so on).
a = tf.Module()
b = tf.Module()
c = tf.Module()
a.b = b
b.c = c
list(a.submodules) == [b, c]
True
list(b.submodules) == [c]
True
list(c.submodules) == []
True

  trainable_variables   Sequence of trainable variables owned by this module and its submodules.
Note: this method uses reflection to find variables on the current instance and submodules. For performance reasons you may wish to cache the result of calling this method if you don't expect the return value to change.

  variables   Sequence of variables owned by this module and its submodules.
Note: this method uses reflection to find variables on the current instance and submodules. For performance reasons you may wish to cache the result of calling this method if you don't expect the return value to change.

   Methods with_name_scope View source
@classmethod
with_name_scope(
    method
)
 Decorator to automatically enter the module name scope.
class MyModule(tf.Module):
  @tf.Module.with_name_scope
  def __call__(self, x):
    if not hasattr(self, 'w'):
      self.w = tf.Variable(tf.random.normal([x.shape[1], 3]))
    return tf.matmul(x, self.w)
 Using the above module would produce tf.Variables and tf.Tensors whose names included the module name:
mod = MyModule()
mod(tf.ones([1, 2]))
<tf.Tensor: shape=(1, 3), dtype=float32, numpy=..., dtype=float32)>
mod.w
<tf.Variable 'my_module/Variable:0' shape=(2, 3) dtype=float32,
numpy=..., dtype=float32)>

 Args
  method   The method to wrap.

 Returns   The original method wrapped such that it enters the module's name scope.


tf.name_scope     View source on GitHub    A context manager for use when defining a Python op.
tf.name_scope(
    name
)
 This context manager pushes a name scope, which will make the name of all operations added within it have a prefix. For example, to define a new Python op called my_op: def my_op(a, b, c, name=None):
  with tf.name_scope("MyOp") as scope:
    a = tf.convert_to_tensor(a, name="a")
    b = tf.convert_to_tensor(b, name="b")
    c = tf.convert_to_tensor(c, name="c")
    # Define some computation that uses `a`, `b`, and `c`.
    return foo_op(..., name=scope)
 When executed, the Tensors a, b, c, will have names MyOp/a, MyOp/b, and MyOp/c. Inside a tf.function, if the scope name already exists, the name will be made unique by appending _n. For example, calling my_op the second time will generate MyOp_1/a, etc.

 Args
  name   The prefix to use on all names created within the name scope.

 Raises
  ValueError   If name is not a string.

 Attributes
  name
   Methods __enter__ View source
__enter__()
 Start the scope block.

 Returns   The scope name.
 __exit__ View source
__exit__(
    type_arg, value_arg, traceback_arg
)


Module: tf.nest Public API for tf.nest namespace. Functions assert_same_structure(...): Asserts that two structures are nested in the same way. flatten(...): Returns a flat list from a given nested structure. is_nested(...): Returns true if its input is a collections.abc.Sequence (except strings). map_structure(...): Applies func to each entry in structure and returns a new structure. pack_sequence_as(...): Returns a given flattened sequence packed into a given structure.


tf.nest.assert_same_structure     View source on GitHub    Asserts that two structures are nested in the same way.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.nest.assert_same_structure
tf.nest.assert_same_structure(
    nest1, nest2, check_types=True, expand_composites=False
)
 Note that namedtuples with identical name and fields are always considered to have the same shallow structure (even with check_types=True). For instance, this code will print True: def nt(a, b):
  return collections.namedtuple('foo', 'a b')(a, b)
print(assert_same_structure(nt(0, 1), nt(2, 3)))

 Args
  nest1   an arbitrarily nested structure.
  nest2   an arbitrarily nested structure.
  check_types   if True (default) types of sequences are checked as well, including the keys of dictionaries. If set to False, for example a list and a tuple of objects will look the same if they have the same size. Note that namedtuples with identical name and fields are always considered to have the same shallow structure. Two types will also be considered the same if they are both list subtypes (which allows "list" and "_ListWrapper" from trackable dependency tracking to compare equal).
  expand_composites   If true, then composite tensors such as tf.sparse.SparseTensor and tf.RaggedTensor are expanded into their component tensors.

 Raises
  ValueError   If the two structures do not have the same number of elements or if the two structures are not nested in the same way.
  TypeError   If the two structures differ in the type of sequence in any of their substructures. Only possible if check_types is True.


tf.nest.flatten     View source on GitHub    Returns a flat list from a given nested structure.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.nest.flatten
tf.nest.flatten(
    structure, expand_composites=False
)
 If nest is not a structure , tuple (or a namedtuple), dict, or an attrs class, then returns a single-element list: [nest]. In the case of dict instances, the sequence consists of the values, sorted by key to ensure deterministic behavior. This is true also for OrderedDict instances: their sequence order is ignored, the sorting order of keys is used instead. The same convention is followed in pack_sequence_as. This correctly repacks dicts and OrderedDicts after they have been flattened, and also allows flattening an OrderedDict and then repacking it back using a corresponding plain dict, or vice-versa. Dictionaries with non-sortable keys cannot be flattened. Users must not modify any collections used in nest while this function is running. Examples:  Python dict (ordered by key):
dict = { "key3": "value3", "key1": "value1", "key2": "value2" }
tf.nest.flatten(dict)
['value1', 'value2', 'value3']
  For a nested python tuple:
tuple = ((1.0, 2.0), (3.0, 4.0, 5.0), (6.0))
tf.nest.flatten(tuple)
    [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
  Numpy array (will not flatten):
array = np.array([[1, 2], [3, 4]])
tf.nest.flatten(array)
    [array([[1, 2],
            [3, 4]])]

tf.Tensor (will not flatten):
tensor = tf.constant([[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]])
tf.nest.flatten(tensor)
    [<tf.Tensor: shape=(3, 3), dtype=float32, numpy=
      array([[1., 2., 3.],
             [4., 5., 6.],
             [7., 8., 9.]], dtype=float32)>]

 Args
  structure   an arbitrarily nested structure. Note, numpy arrays are considered atoms and are not flattened.
  expand_composites   If true, then composite tensors such as tf.sparse.SparseTensor and tf.RaggedTensor are expanded into their component tensors.

 Returns   A Python list, the flattened version of the input.

 Raises
  TypeError   The nest is or contains a dict with non-sortable keys.


tf.nest.is_nested     View source on GitHub    Returns true if its input is a collections.abc.Sequence (except strings).  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.nest.is_nested
tf.nest.is_nested(
    seq
)

 Args
  seq   an input sequence.

 Returns   True if the sequence is a not a string and is a collections.abc.Sequence or a dict.


tf.nest.map_structure     View source on GitHub    Applies func to each entry in structure and returns a new structure.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.nest.map_structure
tf.nest.map_structure(
    func, *structure, **kwargs
)
 Applies func(x[0], x[1], ...) where x[i] is an entry in structure[i]. All structures in structure must have the same arity, and the return value will contain results with the same structure layout. Examples:  A single Python dict:
a = {"hello": 24, "world": 76}
tf.nest.map_structure(lambda p: p * 2, a)
{'hello': 48, 'world': 152}
  Multiple Python dictionaries:
d1 = {"hello": 24, "world": 76}
d2 = {"hello": 36, "world": 14}
tf.nest.map_structure(lambda p1, p2: p1 + p2, d1, d2)
{'hello': 60, 'world': 90}

 Args
  func   A callable that accepts as many arguments as there are structures.
  *structure   scalar, or tuple or dict or list of constructed scalars and/or other tuples/lists, or scalars. Note: numpy arrays are considered as scalars.
  **kwargs   Valid keyword args are:
check_types: If set to True (default) the types of iterables within the structures have to be same (e.g. map_structure(func, [1], (1,)) raises a TypeError exception). To allow this set this argument to False. Note that namedtuples with identical name and fields are always considered to have the same shallow structure.
expand_composites: If set to True, then composite tensors such as tf.sparse.SparseTensor and tf.RaggedTensor are expanded into their component tensors. If False (the default), then composite tensors are not expanded.

 Returns   A new structure with the same arity as structure, whose values correspond to func(x[0], x[1], ...) where x[i] is a value in the corresponding location in structure[i]. If there are different sequence types and check_types is False the sequence types of the first structure will be used.

 Raises
  TypeError   If func is not callable or if the structures do not match each other by depth tree.
  ValueError   If no structure is provided or if the structures do not match each other by type.
  ValueError   If wrong keyword arguments are provided.


tf.nest.pack_sequence_as     View source on GitHub    Returns a given flattened sequence packed into a given structure.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.nest.pack_sequence_as
tf.nest.pack_sequence_as(
    structure, flat_sequence, expand_composites=False
)
 If structure is a scalar, flat_sequence must be a single-element list; in this case the return value is flat_sequence[0]. If structure is or contains a dict instance, the keys will be sorted to pack the flat sequence in deterministic order. This is true also for OrderedDict instances: their sequence order is ignored, the sorting order of keys is used instead. The same convention is followed in flatten. This correctly repacks dicts and OrderedDicts after they have been flattened, and also allows flattening an OrderedDict and then repacking it back using a corresponding plain dict, or vice-versa. Dictionaries with non-sortable keys cannot be flattened.

 Args
  structure   Nested structure, whose structure is given by nested lists, tuples, and dicts. Note: numpy arrays and strings are considered scalars.
  flat_sequence   flat sequence to pack.
  expand_composites   If true, then composite tensors such as tf.sparse.SparseTensor and tf.RaggedTensor are expanded into their component tensors.

 Returns
  packed   flat_sequence converted to have the same recursive structure as structure.

 Raises
  ValueError   If flat_sequence and structure have different element counts.
  TypeError   structure is or contains a dict with non-sortable keys.


Module: tf.nn Wrappers for primitive Neural Net (NN) Operations. Classes class RNNCellDeviceWrapper: Operator that ensures an RNNCell runs on a particular device. class RNNCellDropoutWrapper: Operator adding dropout to inputs and outputs of the given cell. class RNNCellResidualWrapper: RNNCell wrapper that ensures cell inputs are added to the outputs. Functions all_candidate_sampler(...): Generate the set of all classes. atrous_conv2d(...): Atrous convolution (a.k.a. convolution with holes or dilated convolution). atrous_conv2d_transpose(...): The transpose of atrous_conv2d. avg_pool(...): Performs the avg pooling on the input. avg_pool1d(...): Performs the average pooling on the input. avg_pool2d(...): Performs the average pooling on the input. avg_pool3d(...): Performs the average pooling on the input. batch_norm_with_global_normalization(...): Batch normalization. batch_normalization(...): Batch normalization. bias_add(...): Adds bias to value. collapse_repeated(...): Merge repeated labels into single labels. compute_accidental_hits(...): Compute the position ids in sampled_candidates matching true_classes. compute_average_loss(...): Scales per-example losses with sample_weights and computes their average. conv1d(...): Computes a 1-D convolution given 3-D input and filter tensors. conv1d_transpose(...): The transpose of conv1d. conv2d(...): Computes a 2-D convolution given input and 4-D filters tensors. conv2d_transpose(...): The transpose of conv2d. conv3d(...): Computes a 3-D convolution given 5-D input and filters tensors. conv3d_transpose(...): The transpose of conv3d. conv_transpose(...): The transpose of convolution. convolution(...): Computes sums of N-D convolutions (actually cross-correlation). crelu(...): Computes Concatenated ReLU. ctc_beam_search_decoder(...): Performs beam search decoding on the logits given in input. ctc_greedy_decoder(...): Performs greedy decoding on the logits given in input (best path). ctc_loss(...): Computes CTC (Connectionist Temporal Classification) loss. ctc_unique_labels(...): Get unique labels and indices for batched labels for tf.nn.ctc_loss. depth_to_space(...): DepthToSpace for tensors of type T. depthwise_conv2d(...): Depthwise 2-D convolution. depthwise_conv2d_backprop_filter(...): Computes the gradients of depthwise convolution with respect to the filter. depthwise_conv2d_backprop_input(...): Computes the gradients of depthwise convolution with respect to the input. dilation2d(...): Computes the grayscale dilation of 4-D input and 3-D filters tensors. dropout(...): Computes dropout: randomly sets elements to zero to prevent overfitting. elu(...): Computes exponential linear: exp(features) - 1 if < 0, features otherwise. embedding_lookup(...): Looks up embeddings for the given ids from a list of tensors. embedding_lookup_sparse(...): Looks up embeddings for the given ids and weights from a list of tensors. erosion2d(...): Computes the grayscale erosion of 4-D value and 3-D filters tensors. fixed_unigram_candidate_sampler(...): Samples a set of classes using the provided (fixed) base distribution. fractional_avg_pool(...): Performs fractional average pooling on the input. fractional_max_pool(...): Performs fractional max pooling on the input. gelu(...): Compute the Gaussian Error Linear Unit (GELU) activation function. in_top_k(...): Says whether the targets are in the top K predictions. isotonic_regression(...): Solves isotonic regression problems along the given axis. l2_loss(...): L2 Loss. l2_normalize(...): Normalizes along dimension axis using an L2 norm. leaky_relu(...): Compute the Leaky ReLU activation function. learned_unigram_candidate_sampler(...): Samples a set of classes from a distribution learned during training. local_response_normalization(...): Local Response Normalization. log_poisson_loss(...): Computes log Poisson loss given log_input. log_softmax(...): Computes log softmax activations. lrn(...): Local Response Normalization. max_pool(...): Performs the max pooling on the input. max_pool1d(...): Performs the max pooling on the input. max_pool2d(...): Performs the max pooling on the input. max_pool3d(...): Performs the max pooling on the input. max_pool_with_argmax(...): Performs max pooling on the input and outputs both max values and indices. moments(...): Calculates the mean and variance of x. nce_loss(...): Computes and returns the noise-contrastive estimation training loss. normalize_moments(...): Calculate the mean and variance of based on the sufficient statistics. pool(...): Performs an N-D pooling operation. relu(...): Computes rectified linear: max(features, 0). relu6(...): Computes Rectified Linear 6: min(max(features, 0), 6). safe_embedding_lookup_sparse(...): Lookup embedding results, accounting for invalid IDs and empty features. sampled_softmax_loss(...): Computes and returns the sampled softmax training loss. scale_regularization_loss(...): Scales the sum of the given regularization losses by number of replicas. selu(...): Computes scaled exponential linear: scale * alpha * (exp(features) - 1) separable_conv2d(...): 2-D convolution with separable filters. sigmoid(...): Computes sigmoid of x element-wise. sigmoid_cross_entropy_with_logits(...): Computes sigmoid cross entropy given logits. silu(...): Computes the SiLU or Swish activation function: x * sigmoid(x). softmax(...): Computes softmax activations. softmax_cross_entropy_with_logits(...): Computes softmax cross entropy between logits and labels. softplus(...): Computes softplus: log(exp(features) + 1). softsign(...): Computes softsign: features / (abs(features) + 1). space_to_batch(...): SpaceToBatch for N-D tensors of type T. space_to_depth(...): SpaceToDepth for tensors of type T. sparse_softmax_cross_entropy_with_logits(...): Computes sparse softmax cross entropy between logits and labels. sufficient_statistics(...): Calculate the sufficient statistics for the mean and variance of x. swish(...): Computes the SiLU or Swish activation function: x * sigmoid(x). tanh(...): Computes hyperbolic tangent of x element-wise. top_k(...): Finds values and indices of the k largest entries for the last dimension. weighted_cross_entropy_with_logits(...): Computes a weighted cross entropy. weighted_moments(...): Returns the frequency-weighted mean and variance of x. with_space_to_batch(...): Performs op on the space-to-batch representation of input. zero_fraction(...): Returns the fraction of zeros in value.