当前位置: 首页 > news >正文

tf.math

参考 tf.math - 云+社区 - 腾讯云

目录

一、函数列表

二、重要的API

1、tf.floor

2、tf.log

3、tf.reduce_mean

4、tf.reduce_sum

5、tf.add_n

6、tf.math.top_k

7、tf.math.argmax

8、tf.math.greater_equal

9、tf.math.pow

10、tf.math.multiply

11、tf.math.sqrt

12、tf.math.logical_or

13、tf.math.truediv

14、tf.math.less

15、tf.math.count_nonzero

16、tf.math.scalar_mul

17、tf.math.conj

18、tf.math.floormod

19、tf.math.sigmoid

20、tf.math.scalar_mul

21、tf.math.multiply

22、tf.math.logical_not

23、tf.math.add

24、tf.math.subtract

25、tf.math.add_n


一、函数列表

  • abs(...): 计算张量的绝对值。
  • accumulate_n(...): 返回张量列表的元素和。
  • acos(...): 计算x元素的acos。
  • acosh(...): 计算逆双曲余弦x元素。
  • add(...): 返回x + y元素。
  • add_n(...): 按元素顺序添加所有输入张量。
  • angle(...): 返回复张量(或实张量)的元素参数。
  • argmax(...): 返回一个张量在轴上的最大值的指标。 (deprecated arguments)
  • argmin(...): 返回一个张量横轴方向上值最小的指标。(deprecated arguments)
  • asin(...): 计算x元素的三角反正弦。
  • asinh(...): 计算逆双曲正弦x元素。
  • atan(...): 计算x元素的三角反切。
  • atan2(...): 根据参数的符号计算arctan (y/x)。
  • atanh(...): 计算x元素的逆双曲正切。
  • bessel_i0(...): 计算x元素的贝塞尔i0函数。
  • bessel_i0e(...): 计算x元素的贝塞尔i0e函数。
  • bessel_i1(...): 计算x元素的贝塞尔i1函数。
  • bessel_i1e(...): 计算x元素的贝塞尔i1e函数。
  • betainc(...): 计算正则化不完全积分。
  • bincount(...): 计算整数数组中每个值出现的次数。
  • ceil(...): 返回元素方向上不小于x的最小整数。
  • confusion_matrix(...): 根据预测和标签计算混淆矩阵。
  • conj(...): 返回复数的复共轭。
  • cos(...): 计算cosx元素。
  • cosh(...): 计算x元素的双曲余弦。
  • count_nonzero(...): 计算张量维上非零元素的个数。(deprecated arguments) (deprecated arguments)
  • cumprod(...): 计算张量x沿轴的累积积。
  • cumsum(...): 沿着轴计算张量x的累积和。
  • digamma(...): 计算导数绝对值的对数
  • divide(...): 计算Python风格的x除以y的除法。
  • divide_no_nan(...): 计算一个不安全的除法,如果y为零,该除法返回0。
  • equal(...): 返回(x == y)元素的真值。
  • erf(...):计算x元素的高斯误差函数。
  • erfc(...): 计算x元素的互补误差函数。
  • exp(...): 计算x元素的指数。
  • expm1(...): 计算x - 1元素的指数。
  • floor(...): 返回不大于x的元素最大整数。
  • floordiv(...): 除以x / y元素,四舍五入到最负的整数。
  • floormod(...): 当x < 0 xor y < 0时,返回除法的元素剩余部分。
  • greater(...): 返回元素(x > y)的真值。
  • greater_equal(...): 返回元素的真值(x >= y)。
  • igamma(...): 计算下正则化不完全函数P(a, x)。
  • igammac(...): 计算上正则化不完全函数Q(a, x)。
  • imag(...): 返回复张量(或实张量)的虚部。
  • in_top_k(...): 表示目标是否在前K个预测中。
  • invert_permutation(...): 计算张量的逆置换。
  • is_finite(...): 返回x的哪些元素是有限的。
  • is_inf(...): 返回x的哪些元素是Inf。
  • is_nan(...): 返回x的哪些元素是NaN。
  • is_non_decreasing(...): 如果x不递减,则返回True。
  • is_strictly_increasing(...): 如果x严格递增,则返回True。
  • l2_normalize(...): 使用L2范数沿着维度轴进行标准化。 (deprecated arguments)
  • lbeta(...): 计算,沿最后一个维度减小。
  • less(...): 返回(x < y)元素的真值。
  • less_equal(...): 返回元素的真值(x <= y)。
  • lgamma(...): 计算元素(x)绝对值的对数。
  • log(...): 计算x元素的自然对数。
  • log1p(...): 计算(1 + x)元素的自然对数。
  • log_sigmoid(...): 计算x元素的log sigmoid。
  • log_softmax(...): 计算对数softmax激活。(deprecated arguments)
  • logical_and(...): 返回x和y元素的真值。
  • logical_not(...): 返回NOT x element-wise的真值。
  • logical_or(...): 返回x或y元素的真值。
  • logical_xor(...): 逻辑异或函数。
  • maximum(...): 返回x和y的最大值(即x > y ?x: y)元素方面。
  • minimum(...): 返回x和y的最小值(即x < y ?x: y)元素方面。
  • mod(...): 当x < 0 xor y < 0时,返回除法的元素剩余部分。
  • multiply(...): 返回x * y元素。
  • multiply_no_nan(...): 计算x和y的乘积,如果y是0,即使x是NaN或无穷大,返回0。
  • negative(...): 计算数值负值元素。
  • nextafter(...): 返回元素方向上x1的下一个可表示值。
  • not_equal(...): 返回元素的真值(x != y)。
  • polygamma(...): 计算多元函数。
  • polyval(...): 计算多项式的元素值。
  • pow(...): 计算一个值对另一个值的幂。
  • real(...): 返回复张量(或实张量)的实部。
  • reciprocal(...): 计算x元素的倒数。
  • reduce_all(...): 计算元素跨张量维数的“逻辑和”。(deprecated arguments)
  • reduce_any(...): 计算元素跨张量维数的“逻辑或”。(deprecated arguments)
  • reduce_euclidean_norm(...): 计算元素跨张量维数的欧几里德范数。
  • reduce_logsumexp(...): 计算log(sum(exp(一个张量的维度上的元素))。 (deprecated arguments)
  • reduce_max(...): 计算张量维数中元素的最大值。(deprecated arguments)
  • reduce_mean(...): 计算元素跨张量维数的平均值。
  • reduce_min(...): 计算张量维数中元素的最小值。(deprecated arguments)
  • reduce_prod(...): 计算元素跨张量维数的乘积。 (deprecated arguments)
  • reduce_std(...): 计算元素跨张量维数的标准偏差。
  • reduce_sum(...): 计算张量维数中元素的和。(deprecated arguments)
  • reduce_variance(...): 计算元素跨张量维数的方差。
  • rint(...): 返回最接近x的元素整数。
  • round(...): 元素方面,将张量的值舍入到最近的整数。
  • rsqrt(...): 计算x元素平方根的倒数。
  • scalar_mul(...): 将标量乘以张量或索引切片对象。
  • segment_max(...): 计算张量沿段的最大值。
  • segment_mean(...): 沿张量的段计算平均值。
  • segment_min(...): 计算张量沿段的最小值。
  • segment_prod(...): 沿着张量的段计算乘积。
  • segment_sum(...): 沿着张量的段计算和。
  • sigmoid(...): 计算x元素的sigmoid。
  • sign(...): 返回数字符号的元素指示。
  • sin(...): 计算sin (x)元素。
  • sinh(...): 计算x元素的双曲正弦。
  • softmax(...): 计算softmax激活。(deprecated arguments)
  • softplus(...): 计算softplus: log(exp(features) + 1).
  • softsign(...): 计算softsign: features / (abs(features) + 1).
  • sqrt(...): 计算x元素的平方根。
  • square(...): 计算x元素的平方。
  • squared_difference(...): 返回(x - y)(x - y)元素。
  • subtract(...): 返回x - y元素。
  • tan(...): 计算x元素的tan值。
  • tanh(...): 计算x元素的双曲正切。
  • top_k(...): 查找最后一个维度的k个最大项的值和索引。
  • truediv(...): 使用Python 3的除法运算符语义来分割x / y元素。
  • unsorted_segment_max(...): 计算张量沿段的最大值。
  • unsorted_segment_mean(...): 沿张量的段计算平均值。
  • unsorted_segment_min(...): 计算张量沿段的最小值。
  • unsorted_segment_prod(...): 沿着张量的段计算乘积。
  • unsorted_segment_sqrt_n(...): 计算张量沿段的和除以根号N。
  • unsorted_segment_sum(...): 沿着张量的段计算和。
  • xdivy(...): 如果x == 0返回0,否则返回x / y, elementwise。
  • xlogy(...): 如果x == 0返回0,否则返回x * log(y), elementwise。
  • zero_fraction(...):返回值中0的分数。
  • zeta(...): 计算Hurwitz zeta函数。

二、重要的API

1、tf.floor

返回不大于x的元素最大整数。

tf.math.floor(
    x,
    name=None
)

参数:

  • x: 张量。必须是以下类型之一:bfloat16、half、float32、float64。
  • name: 操作的名称(可选)。

返回值:

  • 与x类型相同的张量。

2、tf.log

计算x元素的自然对数。

tf.math.log(
    x,
    name=None
)

例如,\tiny y=log_e x

参数:

  • x: 张量。必须是以下类型之一:bfloat16、half、float32、float64、complex64、complex128。
  • name: 操作的名称(可选)。

返回值:

  • 一个与x类型相同的张量。

3、tf.reduce_mean

计算元素跨张量维数的平均值。

tf.math.reduce_mean(
    input_tensor,
    axis=None,
    keepdims=False,
    name=None
)

沿着坐标轴给出的维数减少input_张量。除非keepdims为真,否则对于轴上的每一项,张量的秩都会减少1。如果keepdims为真,则使用长度1保留缩减后的维度。如果轴为空,则所有维数都被缩减,并返回一个只有一个元素的张量。

例如:

x = tf.constant([[1., 1.], [2., 2.]])
tf.reduce_mean(x)  # 1.5
tf.reduce_mean(x, 0)  # [1.5, 1.5]
tf.reduce_mean(x, 1)  # [1.,  2.]

参数:

  • input_tensor: 要减少的张量。应该具有数值类型。
  • axis: 要缩小的尺寸。如果没有(默认值),则减少所有维度。必须在[-rank(input_张量),rank(input_张量)]范围内。
  • keepdims: 如果为真,则保留长度为1的缩减维度。
  • name: 操作的名称(可选)。

返回值:

  • 一个减少的张量。

请注意np.mean有一个dtype参数,可用于指定输出类型。默认情况下,这是dtype=float64。另一方面,tf.reduce_mean有一个来自input_张量的攻击类型推断,例如:

x = tf.constant([1, 0, 1, 0])
tf.reduce_mean(x)  # 0
y = tf.constant([1., 0., 1., 0.])
tf.reduce_mean(y)  # 0.5

4、tf.reduce_sum

计算张量维数中元素的和。

tf.math.reduce_sum(
    input_tensor,
    axis=None,
    keepdims=None,
    name=None,
    reduction_indices=None,
    keep_dims=None
)

警告:一些参数是不支持的:(keep_dims)。它们将在未来的版本中被删除。

更新说明:不推荐使用keep_dims,而是使用keepdims。

沿着坐标轴给出的维数减少input_张量。除非keepdims为真,否则对于轴上的每一项,张量的秩都会减少1。如果keepdims为真,则使用长度1保留缩减后的维度。如果轴为空,则所有维数都被缩减,并返回一个只有一个元素的张量。

例:

x = tf.constant([[1, 1, 1], [1, 1, 1]])
tf.reduce_sum(x)  # 6
tf.reduce_sum(x, 0)  # [2, 2, 2]
tf.reduce_sum(x, 1)  # [3, 3]
tf.reduce_sum(x, 1, keepdims=True)  # [[3], [3]]
tf.reduce_sum(x, [0, 1])  # 6
x = tf.constant([[1, 2, 4], [8, 16, 32]])
a = tf.reduce_sum(x, -1)  # [ 9 18 36]

参数:

  • input_tensor:要减少的张量。应该具有数值类型。
  • axis:要缩小的尺寸。如果没有(默认值),则减少所有维度。必须在[-rank(input_张量),rank(input_张量)]范围内。
  • keepdims:如果为真,则保留长度为1的缩减维度。
  • name:操作的名称(可选)。
  • reduction_indices: axis的旧名称(已弃用)。
  • keep_dims: keepdims的弃用别名。

返回值:

  • 简化张量,与input_tensor具有相同的d型。

5、tf.add_n

按顺序对输入的张量进行求和。

tf.add_n(
    inputs,
    name=None
)

在添加之前将indexedslice对象转换为密集张量。

 例如:

a = tf.constant([[3, 5], [4, 8]])
b = tf.constant([[1, 6], [2, 9]])
tf.math.add_n([a, b, a])  # [[7, 16], [10, 25]]

6、tf.math.top_k

tf.math.top_k

tf.math.top_k(
    input,
    k=1,
    sorted=True,
    name=None
)

查找最后一个维度的k个最大项的值和索引。如果输入是一个向量(rank=1),找到向量中k个最大的元素,并将它们的值和索引作为向量输出。因此value [j]是输入的第j个最大的条目,它的索引是index [j]。矩阵(分别地。,计算每一行的前k个条目(resp)。沿着最后一个维度的向量)。因此,

values.shape = indices.shape = input.shape[:-1] + [k]

如果两个元素相等,则首先出现下标元素。

参数:

  • input:一维或更高张量,最后维数至少为k。
  • k: 0-D int32张量。要沿着最后一个维度查找的顶部元素的数量(对于矩阵,沿着每一行查找)。
  • sorted:如果为真,则得到的k个元素将按降序排列。
  • name:操作的可选名称。

返回值:

  • values: 沿最后一个维度切片的k个最大元素。
  • indices: 输入的最后一个维度内的值的索引。

7、tf.math.argmax

返回一个张量在轴上的最大值的指标。

tf.math.argmax(
    input,
    axis=None,
    name=None,
    dimension=None,
    output_type=tf.dtypes.int64
)

参数:

  • input:一个张量。必须是以下类型之一:float32、float64、int32、uint8、int16、int8、complex64、int64、qint8、quint8、qint32、bfloat16、uint16、complex128、half、uint32、uint64。
  • axis:张量。必须是下列类型之一:int32、int64。int32或int64,必须在[-rank(输入),rank(输入)]范围内。描述输入张量的哪个轴要缩小。对于向量,使用axis = 0。
  • output_type:一个可选的tf.DType from: tf.int32, tf.int64。默认为tf.int64。
  • name:操作的名称(可选)。

返回值:

  • 一个输出t_type类型的张量。

例:

import tensorflow as tf

x = tf.constant([[1., 2., 6], [6., 2., 6]])

xShape = tf.shape(x)
z1 = tf.arg_max(x, 1)  # 沿axis=0操作

with tf.Session() as sess:
    xShapeValue, d1 = sess.run([xShape, z1])
    print('shape= %s' % (xShapeValue))
    print(d1)

8、tf.math.greater_equal

在生成的文件中定义:python/ops/gen_math_ops.py,返回元素的真值(x >= y)。

tf.math.greater_equal(
    x,
    y,
    name=None
)

参数:

  • x:张量。必须是下列类型之一:float32、float64、int32、uint8、int16、int8、int64、bfloat16、uint16、half、uint32、uint64。
  • y:张量。必须具有与x相同的类型。
  • name:操作的名称(可选)。

返回值:

  • bool类型的张量。

9、tf.math.pow

计算一个值对另一个值的幂。

tf.math.pow(
    x,
    y,
    name=None
)

给定一个张量x和一个张量y,这个操作计算x和y中对应的\large x^y元素。例如:

x = tf.constant([[2, 2], [3, 3]])
y = tf.constant([[8, 16], [2, 3]])
tf.pow(x, y)  # [[256, 65536], [9, 27]]

参数:

  • x:类型为float16、float32、float64、int32、int64、complex64或complex128的张量
  • y:类型为float16、float32、float64、int32、int64、complex64或complex128的张量
  • name:操作的名称(可选)

返回值:

  • 一个张量

10、tf.math.multiply

逐元素的返回x*y。

tf.math.multiply(
    x,
    y,
    name=None
)

参数:

  • x:张量。必须是以下类型之一:bfloat16、half、float32、float64、uint8、int8、uint16、int16、int32、int64、complex64、complex128
  • y:张量。必须具有与x相同的类型
  • name:操作的名称(可选)

返回值:

  • 一个张量。与x类型相同

11、tf.math.sqrt

计算x元素的平方根。

tf.math.sqrt(
    x,
    name=None
)

参数:

  • x:张量。必须是以下类型之一:bfloat16、half、float32、float64、complex64、complex128。
  • name:操作的名称(可选)。

返回值:

  • 一个张量。与x类型相同。

如果x是稀疏张量,返回稀疏张量(x。指标,tf.math.sqrt (x.value,…),x.dense_shape)

12、tf.math.logical_or

返回x或y元素的真值。

tf.math.logical_or(
    x,
    y,
    name=None
)

参数:

  • x: bool型张量。
  • y: bool型张量。
  • name:操作的名称(可选)。

返回值:

  • bool类型的张量。

13、tf.math.truediv

使用Python 3的除法运算符语义来分割x / y元素。

tf.math.truediv(
    x,
    y,
    name=None
)

注意:最好使用遵循Python除法运算符语义的张量运算符或tf.divide。该函数强制python3除法运算符语义,其中所有整数参数首先转换为浮点类型。这个op是由python3中的普通x / y除法和python2.7中的来自于_future__导入除法生成的。如果需要向下舍入的整数除法,请使用x // y或tf.math.floordiv。x和y必须具有相同的数字类型。如果输入是浮点数,则输出将具有相同的类型。如果输入是整数,则将int8和int16的输入转换为float32, int32和int64的输入转换为float64(匹配Numpy的行为)。

参数:

  • x:数值型张量分子。
  • y:数值型张量分母。
  • name:操作的名称(可选)。

返回值:

  • 用浮点数表示x / y。

可能产生的异常:

  • TypeError: If x and y have different dtypes.

14、tf.math.less

返回(x < y)元素的真值。

tf.math.less(
    x,
    y,
    name=None
)

参数:

  • x:张量。必须是下列类型之一:float32、float64、int32、uint8、int16、int8、int64、bfloat16、uint16、half、uint32、uint64。
  • y:张量。必须具有与x相同的类型。
  • name:操作的名称(可选)。

返回值:

  • bool类型的张量。

15、tf.math.count_nonzero

计算张量维上非零元素的个数。

tf.math.count_nonzero(
    input,
    axis=None,
    keepdims=None,
    dtype=tf.dtypes.int64,
    name=None
)

减少沿轴方向给出的尺寸的输入。除非keepdims为真,否则对于轴上的每一项,张量的秩都会减少1。如果keepdims为真,则使用长度1保留缩减后的维度。如果轴没有项,所有的维数都被缩减,并且返回一个只有一个元素的张量。

例:

x = tf.constant([[0, 1, 0], [1, 1, 0]])
tf.math.count_nonzero(x)  # 3
tf.math.count_nonzero(x, 0)  # [1, 2, 0]
tf.math.count_nonzero(x, 1)  # [1, 2]
tf.math.count_nonzero(x, 1, keepdims=True)  # [[1], [2]]
tf.math.count_nonzero(x, [0, 1])  # 3

例:

x = tf.constant(["", "a", "  ", "b", ""])
tf.math.count_nonzero(x) # 3, with "a", "  ", and "b" as nonzero strings.

参数:

  • input:要减少的张量。应该是数字类型、bool或字符串。
  • axis:要缩小的尺寸。如果没有(默认值),则减少所有维度。必须在[-rank(输入),rank(输入)]范围内。
  • keepdims:如果为真,则保留长度为1的缩减维度。
  • dtype:输出dtype;默认为tf.int64。
  • name:操作的名称(可选)。

返回值:

  • 简化张量(非零值的数目)。

16、tf.math.scalar_mul

将标量乘以张量或索引切片对象。

tf.math.scalar_mul(
    scalar,
    x,
    name=None
)

用于梯度代码中,该代码可能处理indexedslice对象,这些对象很容易乘以标量,但与任意张量相乘的代价更高。

参数:

  • scalar:0-D标量张量。一定知道形状。
  • x:要缩放的张量或索引切片。
  • name:操作的名称(可选)。

返回值:

  • 与x相同类型的标量* x(张量或索引切片)。

17、tf.math.conj

返回复数的复共轭。

tf.math.conj(
    x,
    name=None
)

返回复数的复共轭。给定一个复数张量输入,这个操作返回一个复数张量,它是输入中每个元素的复共轭。输入的复数必须是a+bj的形式,其中a是实数,b是虚数。这个运算返回的复共轭是a-bj的形式。

例如:

tensor 'input' is [-2.25 + 4.75j, 3.25 + 5.75j]

tf.math.conj(输入)= = > [-2.25 - 4.75,3.25 - 5.75 j]

如果x是实数,则返回值不变。

参数:

  • x:共轭张量。必须具有数值类型或变体类型。
  • name:操作的名称(可选)。

返回值:

  • 一个张量,它是x的共轭(具有相同类型)。

可能产生的异常:

  • TypeError: If x is not a numeric tensor.

18、tf.math.floormod

tf.math.floormod(
    x,
    y,
    name=None
)

的确,这遵循Python语义,因为这里的结果与地板划分一致。例如,floor(x / y) * y + mod(x, y) = x。注意:数学。floormod支持广播。

参数:

  • x:张量。必须是下列类型之一:int32、int64、bfloat16、half、float32、float64。
  • y:张量。必须具有与x相同的类型。
  • name:操作的名称(可选)。

返回值:

  • 一个张量。与x类型相同。

19、tf.math.sigmoid

Computes sigmoid of x element-wise.

Aliases:

  • tf.compat.v1.math.sigmoid
  • tf.compat.v1.nn.sigmoid
  • tf.compat.v1.sigmoid
  • tf.compat.v2.math.sigmoid
  • tf.compat.v2.nn.sigmoid
  • tf.compat.v2.sigmoid
  • tf.nn.sigmoid
  • tf.sigmoid
tf.math.sigmoid(
    x,
    name=None
)

Specifically, y = 1 / (1 + exp(-x)).

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.

Scipy Compatibility

Equivalent to scipy.special.expit

20、tf.math.scalar_mul

Multiplies a scalar times a Tensor or IndexedSlices object.

Aliases:

  • tf.compat.v1.math.scalar_mul
  • tf.compat.v1.scalar_mul
  • 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.

21、tf.math.multiply

Returns x * y element-wise.

Aliases:

  • tf.RaggedTensor.mul
  • tf.compat.v1.RaggedTensor.mul
  • tf.compat.v1.math.multiply
  • tf.compat.v1.multiply
  • tf.compat.v2.RaggedTensor.mul
  • tf.compat.v2.math.multiply
  • tf.compat.v2.multiply
  • tf.multiply
tf.math.multiply(
    x,
    y,
    name=None
)

NOTE: tf.multiply 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.
  • 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.

22、tf.math.logical_not

Defined in generated file: python/ops/gen_math_ops.py

Returns the truth value of NOT x element-wise.

Aliases:

  • tf.RaggedTensor.invert
  • tf.Tensor.invert
  • tf.compat.v1.RaggedTensor.invert
  • tf.compat.v1.Tensor.invert
  • tf.compat.v1.logical_not
  • tf.compat.v1.math.logical_not
  • tf.compat.v2.RaggedTensor.invert
  • tf.compat.v2.Tensor.invert
  • tf.compat.v2.logical_not
  • tf.compat.v2.math.logical_not
  • tf.logical_not
tf.math.logical_not(
    x,
    name=None
)

Args:

  • x: A Tensor of type bool.
  • name: A name for the operation (optional).

Returns:

  • A Tensor of type bool.

23、tf.math.add

Defined in generated file: python/ops/gen_math_ops.py

Returns x + y element-wise.

Aliases:

  • tf.RaggedTensor.add
  • tf.add
  • tf.compat.v1.RaggedTensor.add
  • tf.compat.v1.add
  • tf.compat.v1.math.add
  • tf.compat.v2.RaggedTensor.add
  • tf.compat.v2.add
  • tf.compat.v2.math.add
tf.math.add(
    x,
    y,
    name=None
)

NOTE: math.add supports broadcasting. AddN does not. More about broadcasting here

Args:

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

24、tf.math.subtract

Returns x - y element-wise.

Aliases:

  • tf.RaggedTensor.sub
  • tf.compat.v1.RaggedTensor.sub
  • tf.compat.v1.math.subtract
  • tf.compat.v1.subtract
  • tf.compat.v2.RaggedTensor.sub
  • tf.compat.v2.math.subtract
  • tf.compat.v2.subtract
  • tf.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.
  • 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.

25、tf.math.add_n

Adds all input tensors element-wise.

Aliases:

  • tf.add_n
  • tf.compat.v1.add_n
  • tf.compat.v1.math.add_n
  • tf.compat.v2.add_n
  • tf.compat.v2.math.add_n
tf.math.add_n(
    inputs,
    name=None
)

Used in the guide:

  • Migrate your TensorFlow 1 code to TensorFlow 2
  • Use a GPU

Used in the tutorials:

  • Neural style transfer

Converts IndexedSlices objects into dense tensors prior to adding.

tf.math.add_n performs the same operation as tf.math.accumulate_n, but it waits for all of its inputs to be ready before beginning to sum. This buffering can result in higher memory consumption when inputs are ready at different times, since the minimum temporary storage required is proportional to the input size rather than the output size.

This op does not broadcast its inputs. If you need broadcasting, use tf.math.add (or the + operator) instead.

For example:

a = tf.constant([[3, 5], [4, 8]])
b = tf.constant([[1, 6], [2, 9]])
tf.math.add_n([a, b, a])  # [[7, 16], [10, 25]]

Args:

  • inputs: A list of tf.Tensor or tf.IndexedSlices objects, each with same shape and type.
  • name: A name for the operation (optional).

Returns:

  • A Tensor of same shape and type as the elements of inputs.

Raises:

  • ValueError: If inputs don't all have same shape and dtype or the shape cannot be inferred.

相关文章:

  • GBase 8c向表中插入数据
  • 想要软考,一般需要多少复习时间?
  • 一起误删cni0虚拟网卡引发的k8s事故
  • QT软件开发-基于FFMPEG设计录屏与rtsp、rtmp推流软件(支持桌面与摄像头)(四)
  • redux中间件函数
  • 【前端面试知识题】- 4.1 JavaScript
  • 客户端架构
  • iOS Xcode 14 创建新项目Pod init及Pod install 报错
  • 金融行业借力泛微今承达,合同统一数字化管理、风险全过程把控
  • 计算机视觉项目实战-基于特征点匹配的图像拼接
  • 软件过程与建模学习之:Individuals,Motivation and Teams
  • 【某南方·高中梦校面试】
  • 三分钟细数几款可视化前端开发工具
  • 【定制项目】【M15 消防安全宣传】主要模块:视频 + 音频 + 图标 + 问答游戏
  • 计算机毕业设计-基于协同过滤算法的旅游管理系统-基于SSM的旅游定制系统(源码+讲解+文档)
  • Java 9 被无情抛弃,Java 8 直接升级到 Java 10!!
  • Koa2 之文件上传下载
  • log4j2输出到kafka
  • Redis的resp协议
  • vue的全局变量和全局拦截请求器
  • windows下mongoDB的环境配置
  • 闭包--闭包之tab栏切换(四)
  • 给新手的新浪微博 SDK 集成教程【一】
  • 基于HAProxy的高性能缓存服务器nuster
  • 事件委托的小应用
  • 手机端车牌号码键盘的vue组件
  • 腾讯优测优分享 | 你是否体验过Android手机插入耳机后仍外放的尴尬?
  • 源码安装memcached和php memcache扩展
  • 3月7日云栖精选夜读 | RSA 2019安全大会:企业资产管理成行业新风向标,云上安全占绝对优势 ...
  • 哈罗单车融资几十亿元,蚂蚁金服与春华资本加持 ...
  • 通过调用文摘列表API获取文摘
  • ###51单片机学习(2)-----如何通过C语言运用延时函数设计LED流水灯
  • #我与Java虚拟机的故事#连载18:JAVA成长之路
  • (04)odoo视图操作
  • (1)(1.8) MSP(MultiWii 串行协议)(4.1 版)
  • (C#)Windows Shell 外壳编程系列9 - QueryInfo 扩展提示
  • (Git) gitignore基础使用
  • (附源码)springboot太原学院贫困生申请管理系统 毕业设计 101517
  • (深度全面解析)ChatGPT的重大更新给创业者带来了哪些红利机会
  • (十)c52学习之旅-定时器实验
  • (实战)静默dbca安装创建数据库 --参数说明+举例
  • (算法设计与分析)第一章算法概述-习题
  • (转)C语言家族扩展收藏 (转)C语言家族扩展
  • (转)GCC在C语言中内嵌汇编 asm __volatile__
  • (转)PlayerPrefs在Windows下存到哪里去了?
  • .chm格式文件如何阅读
  • .NET MVC第三章、三种传值方式
  • .NET 自定义中间件 判断是否存在 AllowAnonymousAttribute 特性 来判断是否需要身份验证
  • .net(C#)中String.Format如何使用
  • .vue文件怎么使用_vue调试工具vue-devtools的安装
  • [ C++ ] STL_stack(栈)queue(队列)使用及其重要接口模拟实现
  • [20180312]进程管理其中的SQL Server进程占用内存远远大于SQL server内部统计出来的内存...
  • [BUG] Authentication Error
  • [C++][基础]1_变量、常量和基本类型
  • [C++]类和对象【下】