tensorflow2.0 基礎二 創建tensor數據操作

方法概要

  • from numpy , list 從numpy創建,或者直接喂list
  • zeros, ones
  • fill
  • random
  • constant
  • Application

From Numpy , List

在這裏插入圖片描述
喂list必須是要tensor能夠支持的格式,如果喂 [ 1, ( 2, 3 ) ] 這樣的機會報錯。

tf.zeros

在這裏插入圖片描述
注意 tf.convert_to_tensor 與 直接創建的區別:

tf.convert_to_tensor([2,3])  #是接收value,Out[16]: <tf.Tensor: id=103, shape=(2,), dtype=int32, numpy=array([2, 3])>
tf.zeros([2,3])              #是接收shape, Out[17]: <tf.Tensor: id=141, shape=(2, 3), dtype=float32, numpy=array([[0., 0., 0.], [0., 0., 0.]], dtype=float32)>

tf.zeros_like

在這裏插入圖片描述
tf.zeros_like = tf.zeros(a.shape)

tf.ones & tf.ones_like

在這裏插入圖片描述
tf.ones_like = tf.ones(a.shape)

Fill

在這裏插入圖片描述

Normal & Truncated_Normal

在這裏插入圖片描述
normal 正態分佈, mean 均值(缺省是0), stddev 方差(缺省是1),
truncated_normal 截斷正態分佈, 截去 Gradient Vanish 梯度消失的部分。

Uniform

在這裏插入圖片描述
uniform 均勻分佈 minval 最小值, maxval 最大值

Random Permutation

在這裏插入圖片描述
Tf.random.shuffle: 隨機打散,洗牌。

Tf.gather: 根據指定的索引轉換對象。可以根據隨機打散後的索引取數據。

tf.constant

在這裏插入圖片描述
Tf.convert_to_tensor 與 tf.constant API基本一樣

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章