日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

TensorFlow学习笔记(十九) 基本算术运算和Reduction归约计算

發布時間:2024/1/23 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TensorFlow学习笔记(十九) 基本算术运算和Reduction归约计算 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

基本運算,變量由tf.constant函數轉化為1階張量。然后計算;現在用tf.reduce_prod()和tf.reduce_sum()函數重新定義,當給定某個tensor張量作為輸入時,這些函數會接收其所有分量,然后分別將它們相乘或相加。

1. 基本算術運算

tf.add(x, y, name=None)
求和

tf.sub(x, y, name=None)
減法

tf.multiply(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


2. 歸約計算(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]


總結

以上是生活随笔為你收集整理的TensorFlow学习笔记(十九) 基本算术运算和Reduction归约计算的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。