最近压力好大,写点东西可能对心情有好处。
reshape即把矩阵的形状变一下,这跟matlab一样的,但如果参数是-1的话是什么意思呢?
看一下例子哈:
. . .
In [21]:
tensor = tf.constant([1, 2, 3, 4, 5, 6, 7,8])
. . .
In [22]:
sess.run(tf.initialize_all_variables())
. . .
In [23]:
print(sess.run(tensor))
print(sess.run(tensor))
[1 2 3 4 5 6 7 8]
. . .
In [24]:
tensorReshape = tf.reshape(tensor,[2,4])
. . .
In [25]:
print(sess.run(tensorReshape))
[[1 2 3 4] [5 6 7 8]]
. . .
In [26]:
tensorReshape = tf.reshape(tensor,[1,2,4])
. . .
In [27]:
print(sess.run(tensorReshape))
[[[1 2 3 4] [5 6 7 8]]]
. . .
In [28]:
tensorResha
tensorReshape = tf.reshape(tensor,[-1,2,2])
. . .
In [29]:
print(sess.run(tensorReshape))
[[[1 2] [3 4]] [[5 6] [7 8]]]所以-1,就是缺省值,就是先以你们合适,到时总数除以你们几个的乘积,我该是几就是几。
. . .
时间: 2024-12-26 13:13:43