数据的填充
1.一阶张量填充
- (1)创建一阶张量
import numpy as np
# 消除tensor运行红色信息
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf
a = tf.reshape(tf.range(9),[9])
print(a)
>>> tf.Tensor([0 1 2 3 4 5 6 7 8], shape=(9,), dtype=int32)
- (2)一阶张量tf.pad应用
# tf.pad()
a = tf.pad(a,[[0,2]])
print(a)
>>> tf.Tensor([0 1 2 3 4 5 6 7 8 0 0], shape=(11,), dtype=int32)
- (3)tf.pad作用讲解
2.二阶张量填充
- (1)创建二阶张量
x = tf.reshape(tf.range(9),[3,3])
print(x)
>>> tf.Tensor(
[[0 1 2]
[3 4 5]
[6 7 8]], shape=(3, 3), dtype=int32)
- (2)二阶张量tf.pad应用
x = tf.pad(x,[[1,2],[2,1]])
print(x)
>>> tf.Tensor(
[[0 0 0 0 0 0]
[0 0 0 1 2 0]
[0 0 3 4 5 0]
[0 0 6 7 8 0]
[0 0 0 0 0 0]
[0 0 0 0 0 0]], shape=(6, 6), dtype=int32)
- (3)tf.pad作用讲解
- (4)数据对比