我对tensorflow并不熟悉,我想知道是否有可能在张量内调整一个维度的大小。
让我有一个给定的张量t:
t = [[1, 10], [2, 20]]
shape(t) = [2, 2]
现在我要修改这个张量的形状,这样:
shape(t) = [2, 3]
到目前为止,我刚刚找到了这些功能:
功能是否符合我所描述的目的?如果没有:为什么?(也许拥有这样的功能是没有意义的?)
亲切的问候
发布于 2017-10-13 21:29:42
使用tf.concat
可以做到这一点。下面是一个例子。
import tensorflow as tf
t = tf.constant([[1, 10], [2, 20]], dtype=tf.int32)
# the new tensor w/ the shape of [2]
TBA_a = tf.constant([3,30], dtype=tf.int32)
# reshape TBA_a to [2,1], then concat it to t on axis 1 (column)
new_t = tf.concat([t, tf.reshape(TBA_a, [2,1])], axis=1)
sess = tf.InteractiveSession()
print(new_t.eval())
它会给我们
[[ 1 10 3]
[ 2 20 30]]
https://stackoverflow.com/questions/46735156
复制