基本算術運算
操作 | 描述 |
---|---|
tf.add(x, y, name=None) | 求和 |
tf.sub(x, y, name=None) | 減法 |
tf.mul(x, y, name=None) | 乘法 |
tf.div(x, y, name=None) | 除法 |
tf.mod(x, y, name=None) | 取模 |
tf.abs(x, name=None) | 求絕對值 |
tf.neg(x, name=None) | 取負 (y = -x). |
tf.sign(x, name=None) | 返回符號 y = sign(x) = -1 if x < 0; 0 if x == 0; 1 if x > 0. |
tf.inv(x, name=None) | 取反 |
tf.square(x, name=None) | 計算平方 (y = x * x = x^2). |
tf.round(x, name=None) | 舍入最接近的整數 # ‘a’ is [0.9, 2.5, 2.3, -4.4] tf.round(a) ==> [ 1.0, 3.0, 2.0, -4.0 ] |
tf.sqrt(x, name=None) | 開根號 (y = \sqrt{x} = x^{1/2}). |
tf.pow(x, y, name=None) | 冪次方 # tensor ‘x’ is [[2, 2], [3, 3]] # tensor ‘y’ is [[8, 16], [2, 3]] tf.pow(x, y) ==> [[256, 65536], [9, 27]] |
tf.exp(x, name=None) | 計算e的次方 |
tf.log(x, name=None) | 計算log,一個輸入計算e的ln,兩輸入以第二輸入為底 |
tf.maximum(x, y, name=None) | 返回最大值 (x > y ? x : y) |
tf.minimum(x, y, name=None) | 返回最小值 (x < y ? x : y) |
tf.cos(x, name=None) | 三角函數cosine |
tf.sin(x, name=None) | 三角函數sine |
tf.tan(x, name=None) | 三角函數tan |
tf.atan(x, name=None) | 三角函數ctan |
矩陣運算
操作 | 描述 |
---|---|
tf.diag(diagonal, name=None) | 返回一個給定對角值的對角tensor # ‘diagonal’ is [1, 2, 3, 4] tf.diag(diagonal) ==> [[1, 0, 0, 0] [0, 2, 0, 0] [0, 0, 3, 0] [0, 0, 0, 4]] |
tf.diag_part(input, name=None) | 功能與上面相反 |
tf.trace(x, name=None) | 求一個2維tensor足跡,即對角值diagonal之和 |
tf.transpose(a, perm=None, name=’transpose’) | 調換tensor的維度順序 按照列表perm的維度排列調換tensor順序, 如為定義,則perm為(n-1…0) # ‘x’ is [[1 2 3],[4 5 6]] tf.transpose(x) ==> [[1 4], [2 5],[3 6]] # Equivalently tf.transpose(x, perm=[1, 0]) ==> [[1 4],[2 5], [3 6]] |
tf.matmul(a, b, transpose_a=False, transpose_b=False, a_is_sparse=False, b_is_sparse=False, name=None) |
矩陣相乘 |
tf.matrix_determinant(input, name=None) | 返回方陣的行列式 |
tf.matrix_inverse(input, adjoint=None, name=None) | 求方陣的逆矩陣,adjoint為True時,計算輸入共軛矩陣的逆矩陣 |
tf.cholesky(input, name=None) | 對輸入方陣cholesky分解, 即把一個對稱正定的矩陣表示成一個下三角矩陣L和其轉置的乘積的分解A=LL^T |
tf.matrix_solve(matrix, rhs, adjoint=None, name=None) | 求解tf.matrix_solve(matrix, rhs, adjoint=None, name=None) matrix為方陣shape為[M,M],rhs的shape為[M,K],output為[M,K] |
復數操作
操作 | 描述 |
---|---|
tf.complex(real, imag, name=None) | 將兩實數轉換為復數形式 # tensor ‘real’ is [2.25, 3.25] # tensor imag is [4.75, 5.75]tf.complex(real, imag) ==> [[2.25 + 4.75j], [3.25 + 5.75j]] |
tf.complex_abs(x, name=None) | 計算復數的絕對值,即長度。 # tensor ‘x’ is [[-2.25 + 4.75j], [-3.25 + 5.75j]] tf.complex_abs(x) ==> [5.25594902, 6.60492229] |
tf.conj(input, name=None) | 計算共軛復數 |
tf.imag(input, name=None) tf.real(input, name=None) |
提取復數的虛部和實部 |
tf.fft(input, name=None) | 計算一維的離散傅里葉變換,輸入數據類型為complex64 |
歸約計算(Reduction)
操作 | 描述 |
---|---|
tf.reduce_sum(input_tensor, reduction_indices=None, keep_dims=False, name=None) |
計算輸入tensor元素的和,或者安照reduction_indices指定的軸進行求和 # ‘x’ is [[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, keep_dims=True) ==> [[3], [3]] tf.reduce_sum(x, [0, 1]) ==> 6 |
tf.reduce_prod(input_tensor, reduction_indices=None, keep_dims=False, name=None) |
計算輸入tensor元素的乘積,或者安照reduction_indices指定的軸進行求乘積 |
tf.reduce_min(input_tensor, reduction_indices=None, keep_dims=False, name=None) |
求tensor中最小值 |
tf.reduce_max(input_tensor, reduction_indices=None, keep_dims=False, name=None) |
求tensor中最大值 |
tf.reduce_mean(input_tensor, reduction_indices=None, keep_dims=False, name=None) |
求tensor中平均值 |
tf.reduce_all(input_tensor, reduction_indices=None, keep_dims=False, name=None) |
對tensor中各個元素求邏輯’與’ # ‘x’ is # [[True, True] # [False, False]] tf.reduce_all(x) ==> False tf.reduce_all(x, 0) ==> [False, False] tf.reduce_all(x, 1) ==> [True, False] |
tf.reduce_any(input_tensor, reduction_indices=None, keep_dims=False, name=None) |
對tensor中各個元素求邏輯’或’ |
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]] |
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] |
序列比較與索引提取(Sequence Comparison and Indexing)
操作 | 描述 |
---|---|
tf.argmin(input, dimension, name=None) | 返回input最小值的索引index |
tf.argmax(input, dimension, name=None) | 返回input最大值的索引index |
tf.listdiff(x, y, name=None) | 返回x,y中不同值的索引 |
tf.where(input, name=None) | 返回bool型tensor中為True的位置 # ‘input’ tensor is #[[True, False] #[True, False]] # ‘input’ 有兩個’True’,那么輸出兩個坐標值. # ‘input’的rank為2, 所以每個坐標為具有兩個維度. where(input) ==> [[0, 0], [1, 0]] |
tf.unique(x, name=None) | 返回一個元組tuple(y,idx),y為x的列表的唯一化數據列表, idx為x數據對應y元素的index # 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] |