tf.reshape中的-1作用:
# tf.reshape( )
import tensorflow as tf
import numpy as np
x = np.array([[[[1],[2],[3]],[[4],[5],[6]]], [[[7],[8],[9]],\
[[10],[11],[12]]], [[[13],[14],[15]],[[16],[17],[18]]]])
print(x) # shape 大小规模为: 3 * 2 * 3 = 18
实例1 :
x_reshape_1 = tf.reshape(x, [-1, 2, 3]) # -1则根据后面的列数2 * 3 = 6 ,自动算出行数 18 / 6 = 3
print(x_reshape_1) # 3 * 2 * 3
执行结果
实例2:
x_reshape_2 = tf.reshape(x, [3, 3, -1]) # 18 / 3 / 3 = 2 计算出行数为 2
print(x_reshape_2) # 3 * 3 * 2
执行结果