好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > TensorFlow2基本操作之合并分割與統計

TensorFlow2基本操作之合并分割與統計

熱門標簽:佛山防封外呼系統收費 南昌辦理400電話怎么安裝 徐州天音防封電銷卡 電話機器人適用業務 鄭州智能外呼系統運營商 湛江電銷防封卡 哈爾濱外呼系統代理商 獲客智能電銷機器人 不錯的400電話辦理

合并與分割

tf.concat

tf.concat可以幫助我們實現拼接操作.

格式:

tf.concat(
    values, axis, name='concat'
)

參數:

  • values: 一個 tensor 或 tensor list
  • axis: 操作的維度
  • name: 數據名稱, 默認為 “concat”

例子:

part_1 = tf.zeros([5, 3])
print(part_1)

part_2 = tf.ones([5, 3])
print(part_2)

# 豎向拼接
result_1 = tf.concat([part_1, part_2], axis=0)
print(result_1)

# 橫向拼接
result_2 = tf.concat([part_1, part_2], axis=1)
print(result_2)

輸出結果:

tf.Tensor(
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]], shape=(5, 3), dtype=float32)
tf.Tensor(
[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]], shape=(5, 3), dtype=float32)
tf.Tensor(
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]], shape=(10, 3), dtype=float32)
tf.Tensor(
[[0. 0. 0. 1. 1. 1.]
[0. 0. 0. 1. 1. 1.]
[0. 0. 0. 1. 1. 1.]
[0. 0. 0. 1. 1. 1.]
[0. 0. 0. 1. 1. 1.]], shape=(5, 6), dtype=float32)

tf.stack

rf.stack可以創建一個新的維度來合并兩個張量.

格式:

tf.stack(
    values, axis=0, name='stack'
)

參數:

  • values: 一個 tensor list
  • axis: 操作的維度
  • name: 數據名稱, 默認為 “stack”

例子:

part_1 = tf.zeros([5, 3])
print(part_1)

part_2 = tf.ones([5, 3])
print(part_2)

# 頭拼接
result_1 = tf.stack([part_1, part_2], axis=0)
print(result_1)

# 尾拼接
result_2 = tf.stack([part_1, part_2], axis=2)
print(result_2)

輸出結果:

tf.Tensor(
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]], shape=(5, 3), dtype=float32)
tf.Tensor(
[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]], shape=(5, 3), dtype=float32)
tf.Tensor(
[[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]

[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]], shape=(2, 5, 3), dtype=float32)
tf.Tensor(
[[[0. 1.]
[0. 1.]
[0. 1.]]

[[0. 1.]
[0. 1.]
[0. 1.]]

[[0. 1.]
[0. 1.]
[0. 1.]]

[[0. 1.]
[0. 1.]
[0. 1.]]

[[0. 1.]
[0. 1.]
[0. 1.]]], shape=(5, 3, 2), dtype=float32)

tf.unstack

tf.unstack是一個矩陣分解函數.

格式:

# unstack
tf.unstack(
value, num=None, axis=0, name='unstack'
)

參數:

  • values: 一個 tensor, 維度大于 0
  • num: 軸的長度
  • axis: 操作的維度
  • name: 數據名稱, 默認為 “unstack”

例子:

a = tf.stack([tf.zeros([5, 3]), tf.ones([5, 3])], axis=0)
print(a)

b = tf.unstack(a, axis=0)
print(b)

輸出結果:

tf.Tensor(
[[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]

[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]], shape=(2, 5, 3), dtype=float32)
[tf.Tensor: shape=(5, 3), dtype=float32, numpy=
array([[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]], dtype=float32)>, tf.Tensor: shape=(5, 3), dtype=float32, numpy=
array([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]], dtype=float32)>]

tf.split

tf.split()可以把一個張量劃分為幾個子張量.

格式:

tf.split(
    value, num_or_size_splits, axis=0, num=None, name='split'
)

參數:

  • value: 待切分的張量
  • num_or_size_splits: 切成幾份
  • axis: 操作的維度
  • num: num_or_size_splits 不能實現的情況下使用
  • name: 數據名稱, 默認為 “split”

例子:

# split
a = tf.stack([tf.zeros([5, 3]), tf.ones([5, 3])], axis=0)
print(a)

b = tf.split(a, 2)
print(b)

輸出結果:

tf.Tensor(
[[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]

[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]], shape=(2, 5, 3), dtype=float32)
[tf.Tensor: shape=(1, 5, 3), dtype=float32, numpy=
array([[[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]]], dtype=float32)>, tf.Tensor: shape=(1, 5, 3), dtype=float32, numpy=
array([[[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]]], dtype=float32)>]

數據統計

tf.norm

tf.norm可以幫助我們計算向量, 矩陣, 張量的范數.

格式:

tf.norm(
    tensor, ord='euclidean', axis=None, keepdims=None, name=None
)

參數:

  • tensor: 輸入的張量
  • ord: 范數的順序
  • axis: 操作的維度
  • keep_dims: 如果為 True, 則 axis 中指定的軸將保持為大小 1
  • name: 數據名稱

例子:

a = tf.fill([2, 2], 2.0)
print(a)

# sqrt(2^2 * 4) = sqrt(16) = 4
b = tf.norm(a)
print(b)

# [2 + 2, 2 + 2] = [4, 4]
c = tf.norm(a, ord=1, axis= 0)
print(c)

# [sqrt(2^2 + 2^2), sqrt(2^2 + 2^2)] = [sqrt(8), sqrt(8)]
d = tf.norm(a, ord=2, axis= 0)
print(d)

輸出結果:

tf.Tensor(
[[2. 2.]
[2. 2.]], shape=(2, 2), dtype=float32)
tf.Tensor(4.0, shape=(), dtype=float32)
tf.Tensor([4. 4.], shape=(2,), dtype=float32)
tf.Tensor([2.828427 2.828427], shape=(2,), dtype=float32)

reduce_min/max/mean

計算一個張量各個維度上元素的最小值 / 最大值 / 平均值.

格式:

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

參數:

  • input_tensor: 傳入的張量
  • axis: 維度, 默認計算所有維度
  • keepdims: 如果為真保留維度, 默認為 False
  • name: 數據名稱

例子:

a = tf.reshape(tf.range(9), [3, 3])
print(a)

min = tf.reduce_min(a)
print(min)

max = tf.reduce_max(a)
print(max)

輸出結果:

tf.Tensor(
[[0 1 2]
[3 4 5]
[6 7 8]], shape=(3, 3), dtype=int32)
tf.Tensor(0, shape=(), dtype=int32)
tf.Tensor(8, shape=(), dtype=int32)

argmax / argmin

tf.argmax/tf.argmin可以幫我們找到最大 / 最小值所在的索引 (index).

格式:

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

參數:

  • input: 輸入
  • axis: 操作的維度
  • output_type: 輸出數據類型, 默認為 int64
  • name: 數據名稱

例子:

# argmax / argmin
a = tf.reshape(tf.range(9), [3, 3])
print(a)

max = tf.argmax(a)
print(max)

min = tf.argmin(a)
print(min)

輸出結果:

tf.Tensor(
[[0 1 2]
[3 4 5]
[6 7 8]], shape=(3, 3), dtype=int32)
tf.Tensor([2 2 2], shape=(3,), dtype=int64)
tf.Tensor([0 0 0], shape=(3,), dtype=int64)

tf.equal

tf.equal可以幫助我們判斷兩個張量是否相等. 返回 True / False.

格式:

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

例子:

a = tf.zeros(5, dtype=tf.float32)
print(a)

b = tf.range(5, dtype=tf.float32)
print(b)

print(tf.equal(a, b))

輸出結果:

tf.Tensor([0. 0. 0. 0. 0.], shape=(5,), dtype=float32)
tf.Tensor([0. 1. 2. 3. 4.], shape=(5,), dtype=float32)
tf.Tensor([ True False False False False], shape=(5,), dtype=bool)

tf.unique

tf.unique可以幫我們找出張量中不重復的值

格式:

tf.unique(
    x, out_idx=tf.dtypes.int32, name=None
)

參數:

  • input: 輸入
  • output_type: 輸出數據類型, 默認為 int32
  • name: 數據名稱

例子:

a = tf.range(5)
print(tf.unique(a))

b = tf.constant([4, 2, 2, 4, 3])
print(tf.unique(b))

輸出結果:

Unique(y=tf.Tensor: shape=(5,), dtype=int32, numpy=array([0, 1, 2, 3, 4])>, idx=tf.Tensor: shape=(5,), dtype=int32, numpy=array([0, 1, 2, 3, 4])>)
Unique(y=tf.Tensor: shape=(3,), dtype=int32, numpy=array([4, 2, 3])>, idx=tf.Tensor: shape=(5,), dtype=int32, numpy=array([0, 1, 1, 0, 2])>)

到此這篇關于一小時學會TensorFlow2基本操作之合并分割與統計的文章就介紹到這了,更多相關TensorFlow2合并分割與統計內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • 手把手教你使用TensorFlow2實現RNN
  • tensorflow2.0實現復雜神經網絡(多輸入多輸出nn,Resnet)
  • windows系統Tensorflow2.x簡單安裝記錄(圖文)
  • 詳解TensorFlow2實現前向傳播
  • Python強化練習之Tensorflow2 opp算法實現月球登陸器

標簽:安康 懷化 廣西 吉安 蘭州 紹興 蕪湖 呂梁

巨人網絡通訊聲明:本文標題《TensorFlow2基本操作之合并分割與統計》,本文關鍵詞  TensorFlow2,基本操作,之,合并,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《TensorFlow2基本操作之合并分割與統計》相關的同類信息!
  • 本頁收集關于TensorFlow2基本操作之合并分割與統計的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 半夜开车发出疼的声音| 亚洲综合另类 | 亚洲好逼| 日本xxxx护士hd| 欧美黄色网| 大地资源三在线观看8| 高清69xxxxxxxxx| 女人笫一次一级毛片| 俄罗斯激情女同互慰在线| 小青年乡村猎艳| 韩国一级淫片视频免费播放| 韩国特黄毛片一级毛片免费 | 瑜伽裤精品一区二区| 色婷婷综合久久久久精品| 国产熟妇丰满熟妇视频香港红灯区| 在线观看国产精品色花堂| 美女露出胸让男人亲| 精品国产三级A∨在线观看| 99热最新网址获取| 另类尿喷潮videofree| 国产亲子伦一级A片免费看| 《教室》大尺度片段| 下面出水了好想要好爽| 在线视频成人| 午夜黄色一级片| 国产精品久久久久久久久免费丝袜| 特级揪痧毛片| 欧美日韩国产三级| 国产精品国产精品| 国产精品盗摄?偷窥盗摄| 2022国产91精品久久久久久| 福利视频app导航在线观看| 丰满的岳?v66Av| 小受被小攻按住吸乳漫画| 日韩va亚洲va欧美va浪潮| 欧美性色黄| 乱子伦一区二区三区高清免费| JLZZJLZZ亚洲乱熟无码| 欧美伊香蕉久久综合网99| 好吊淫视频| 桃花岛亚洲精品tv自拍网站|