0
点赞
收藏
分享

微信扫一扫

tf.reshape

木樨点点 2023-01-16 阅读 127


import tensorflow as tf
t=tf.constant([1, 2, 3, 4, 5, 6, 7, 8, 9])
tf.reshape(t, [3, 3])

t=tf.constant( [
[[1, 1], [2, 2]],
[[3, 3], [4, 4]]
])
# tensor 't' has shape [2, 2, 2]
tf.reshape(t, [2, 4])

<tf.Tensor: shape=(2, 4), dtype=int32, numpy=
array([[1, 1, 2, 2],
[3, 3, 4, 4]], dtype=int32)>

t=tf.constant([[[1, 1, 1],
[2, 2, 2]],
[[3, 3, 3],
[4, 4, 4]],
[[5, 5, 5],
[6, 6, 6]]])

tf.reshape(t, [-1])
Out[113]: <tf.Tensor: shape=(18,), dtype=int32, numpy=array([1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6], dtype=int32)>

tf.reshape(t, [2, -1])
Out[114]:
<tf.Tensor: shape=(2, 9), dtype=int32, numpy=
array([[1, 1, 1, 2, 2, 2, 3, 3, 3],
[4, 4, 4, 5, 5, 5, 6, 6, 6]], dtype=int32)>

tf.reshape(t, [-1, 9])
Out[115]:
<tf.Tensor: shape=(2, 9), dtype=int32, numpy=
array([[1, 1, 1, 2, 2, 2, 3, 3, 3],
[4, 4, 4, 5, 5, 5, 6, 6, 6]], dtype=int32)>

tf.reshape(t, [ 2, -1, 3]) 
Out[116]:
<tf.Tensor: shape=(2, 3, 3), dtype=int32, numpy=
array([[[1, 1, 1],
[2, 2, 2],
[3, 3, 3]],

[[4, 4, 4],
[5, 5, 5],
[6, 6, 6]]], dtype=int32)>


举报

相关推荐

pytorch的tf.reshape

测试reshape

reshape2

theano reshape -1

reshape包使用

Tensorflow的reshape用法

0 条评论