1.維度變換
import tensorflow as tf
import numpy as np
print(tf.__version__)
a = tf.random.normal([4, 28, 28, 3])
print(a.shape)
print(tf.reshape(a, [4, 784, 3]).shape)
print(tf.reshape(a, [4, -1]).shape)
2.矩陣的轉置
a = tf.random.normal((4, 3, 2, 1))
print(a.shape)
print(tf.transpose(a).shape)
a = tf.random.normal((4, 28, 28, 3))
print(a.shape)
print(tf.transpose(a, [0, 3, 1, 2]).shape)
3.增加 展開維度
a = tf.random.normal([4, 35, 8])
print(a.shape)
print(tf.expand_dims(a, axis=0).shape)
print(a.shape)
print(tf.expand_dims(a, axis=3).shape)
4.壓縮維度
a = tf.zeros([1, 2, 1, 1 ,3])
print(a.shape)
print(tf.squeeze(a).shape)
print(a.shape)
print(tf.squeeze(a, axis=2).shape)