python - 为什么 Tensorflow 转置在特定场景下失败?

标签 python tensorflow

tf.reset_default_graph()

sess=tf.Session()

X=tf.placeholder(tf.float32, shape=[3,8])

X_1 = tf.reshape(X,[3,2,4])

print(X_1)

X_tensor = tf.transpose(X_1,[1,2,0])

print(X_tensor)

输出:

Tensor("Reshape:0", shape=(3, 2, 4), dtype=float32)

Tensor("transpose:0", shape=(2, 4, 3), dtype=float32)

转置结果应为(4,3,2)

最佳答案

您将 perm=[1,2,0] 传递给 tf.transpose,这就是您得到 (2, 4, 3) 的原因> 作为 (3, 2, 4) 的形状。 (参见:https://www.tensorflow.org/api_docs/python/tf/transpose)

尝试 X_tensor = tf.transpose(X_1,[2,0,1]) 以获得您想要的结果。

关于python - 为什么 Tensorflow 转置在特定场景下失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55231985/

相关文章:

python - ValueError : Layer leaky_re_lu_1 was called with an input that isn't a symbolic tensor. 接收类型:<class 'keras.layers.convolutional.Conv3D' >

python - tf.nn.depthwise_conv2d 太慢了。正常吗?

python - 带有 C 扩展的可执行 Python Zip

python - RDD 问题 - 列表索引超出范围

python - 修改python中的位串

tensorflow - 如何用元信息丰富卷积神经网络?

tensorflow - keras Conv2d值错误: Negative dimension size

python - 使用 Cython 和 "next"编译

python - IMAP 获取正文太慢

python - 如何为 TensorBoard 图像添加标签?