首页 > 解决方案 > tensorflow einsum 跟踪错误?

问题描述

为什么这些输出不同?这是预期的行为吗?我正在使用张量流 1.12

import tensorflow as tf

matrix = tf.constant([[1, 2, 3],
                      [4, 5, 6],
                      [7, 8, 9]])

with tf.Session() as sess:
    print(tf.einsum('ii',matrix).eval())

# 45

尽管

import numpy as np

np.einsum('ii',[[1, 2, 3],
                [4, 5, 6],
                [7, 8, 9]])
# 15 (as it should be)

为什么 tensorflow 的 einsum 对矩阵的所有元素求和?

更新:我在 GitHub 上打开了一个问题,它看起来像一个错误。

标签: pythonnumpytensorflow

解决方案


这已在 PR 25079 中修复并合并。


推荐阅读