Tensorflow API Math

来源:互联网 发布:sd照片恢复软件 编辑:程序博客网 时间:2024/05/29 08:11

Math

Arithmetic Operators

tf.add(x, y, name=None)   # 求和tf.subtract(x, y, name=None) # 减法tf.multiply(x, y, name=None)  # 乘法tf.div(x, y, name=None)  # 除法tf.mod(x, y, name=None)  # 取模

Basic Math Functions

tf.abs(x, name=None)  # 取绝对值 y=|x|tf.negative(x, name=None)  # 取反 y = -xtf.sign(x, name=None)  # 取符号 sign(x)=-1 if x<0;0 if x==0; 1 if x>0tf.square(x, name=None)  # 取平方 y = x^2tf.sqrt(x, name=None)  # 取开方 y = x^(1/2)tf.pow(x, y, name=None) # 幂次方 x^ytf.exp(x, name=None) #  e的x次方, e^xtf.log(x, y, name=None)  # log, 一个输入计算lnx, 两个输入计算 log_y(x) tf.ceil(x, name=None)  # 取比x大的最小正数tf.floor(x, name=None)  # 取比x小的最大整数tf.round(x, name=None) # 取最接近的整数tf.maximum(x, y, name=None) # 取最大值(x>y ? x:y)tf.minimum(x, y, name=None) # 取最小值 (x<y ? x:y)tf.sin(x, name=None) # 三角函数 sin(x)tf.cos(x, name=None)  # 三角函数 cos(x)tf.tan(x, name=None)  # 三角函数 tan(x)tf.atan(x, name=None)  # 三角函数 arctan(x)

Matrix Math Functions

tf.diag(diagonal, name=None)  # 返回以给定值为对角值的对角矩阵 tf.diag_part(input,name=None)  # 与diag相反tf.transpose(a, perm=None, name='transpose') # 矩阵的维度调整,perm指定维度(二维转置) tf.tf.matmul(a,b,name=None)  # 矩阵乘tf.matrix_determinant(input,name=None)  # 行列式(方阵), 类型为: float32, float64tf.matrix_inverse(input,adjoint=None,name=None)  # 矩阵的逆tf.cholesky(input,name=None)  # 矩阵(方阵)的cholesky分解qr(input,full_matrices=None,name=None) # 矩阵的 QR 分解svd(tensor,full_matrices=False,compute_uv=True,name=None)  # 矩阵的 SVD 分解

Tensor Math Function

tf.tensordot(a, b, axes, name=None)  # 张量相乘

Complex Number Functions

tf.complex(real, imag, name=None) # 将两个实数转换为复数形式tf.conj(x, name=None)  # 计算共轭复数tf.imag(input,name=None) # 返回虚部tf.real(input,name=None) # 返回实部

Reduction

# input_tensor 输入的tensor   reduction_indices 指定轴  keep_dims 保持维度tf.reduce_sum(input_tensor, reduction_indices=None, keep_dims=False, name=None)  # 取和tf.reduce_prod(input_tensor, reduction_indices=None, keep_dims=False, name=None) # 取乘积tf.reduce_min(input_tensor, reduction_indices=None, keep_dims=False, name=None) # 取最小值tf.reduce_max(input_tensor, reduction_indices=None, keep_dims=False, name=None) # 取最大值tf.reduce_mean(input_tensor, reduction_indices=None, keep_dims=False, name=None) # 取平均值tf.reduce_all(input_tensor, reduction_indices=None, keep_dims=False, name=None) # 逻辑'与'tf.reduce_any(input_tensor, reduction_indices=None, keep_dims=False, name=None) # 逻辑'或'tf.accumulate_n(inputs, shape=None, tensor_dtype=None, name=None) # 计算一系列tensor的和# tensor ‘a’ is [[1, 2], [3, 4]]; tensor b is [[5, 0], [0, 6]]tf.accumulate_n([a, b, a]) #  [[7, 4], [6, 14]]

Scan

tf.cumsum(x, axis=0, exclusive=False, reverse=False, name=None)   # 累积求和tf.cumsum([a, b, c]) ==> [a, a + b, a + b + c]tf.cumsum([a, b, c], exclusive=True) ==> [0, a, a + b]tf.cumsum([a, b, c], reverse=True) ==> [a + b + c, b + c, c]tf.cumsum([a, b, c], exclusive=True, reverse=True) ==> [b + c, c, 0]tf.cumprod(x, axis=0, exclusive=False, reverse=False, name=None)   # 累积求积tf.cumprod([a, b, c]) ==> [a, a * b, a * b * c]tf.cumprod([a, b, c], exclusive=True) ==> [0, a, a * b]tf.cumprod([a, b, c], reverse=True) ==> [a * b * c, b * c, c]tf.cumprod([a, b, c], exclusive=True, reverse=True) ==> [b * c, c, 0]

Segmentation

tf.segment_sum(data, segment_ids, name=None) # 沿着segment_ids指定维度分割张量,并累加求和# c = tf.constant([[1,2,3,4], [-1,-2,-3,-4], [5,6,7,8]])# tf.segment_sum(c, tf.constant([0, 0, 1]))  ==> [[0 0 0 0] [5 6 7 8]]# [1, 2, 3, 4] + [-1, -2, -3, -4] = [0, 0, 0, 0]    , [5, 6, 7, 8]=[5, 6, 7, 8]tf.segment_prod(data, segment_ids, name=None) # 沿着segment_ids指定维度分割张量,并累加求积tf.segment_min(data, segment_ids, name=None)  # 沿着segment_ids指定维度分割张量,并取最小值tf.segment_max(data, segment_ids, name=None)  # 沿着segment_ids指定维度分割张量,并取最大值tf.segment_mean(data, segment_ids, name=None)   # 沿着segment_ids指定维度分割张量,并取平均值tf.unsorted_segment_sum(data, segment_ids,num_segments, name=None)  # 与tf.segment_sum函数类似,但segment_ids可以无序tf.sparse_segment_sum(data, indices, segment_ids, name=None)    # 先选取,再分割

Sequence Comparison and Indexing

tf.argmin(input, dimension, name=None)  # 返回input最小值的索引indextf.argmax(input, dimension, name=None)  # 返回input最大值的索引indextf.setdiff1d(x, y, index_dtype=tf.int32, name=None) # 返回x,y中不同值及其索引# x = [1,2,3,4,5], y = [1,3,4,6]# t = tf.setdiff1d(x,y)    z ==> [2, 5]  ind ==> [1,4]tf.where(input, name=None)    # 返回bool型tensor中为True的位置# ‘input’ tensor is [[True, False], [True, False]]# where(input) ==>[[0, 0], [1, 0]]tf.unique(x, name=None) # 返回一个元组tuple(y,idx),y为x的列表的唯一化数据列表,# tensor ‘x’ is [1, 1, 2, 4, 4, 4, 7, 8, 8]     y, idx = unique(x)# y ==> [1, 2, 4, 7, 8]        idx ==> [0, 0, 1, 2, 2, 2, 3, 4, 4]tf.invert_permutation(x, name=None)  # 置换x数据与索引# tensor x is [3, 4, 0, 2, 1]    invert_permutation(x) ==> [2, 4, 3, 0, 1]
原创粉丝点击