tf.norm error ValueError: 'ord' must be a supported vector norm, got fro

tf.norm error ValueError: 'ord' must be a supported vector norm, got fro

我正在尝试计算张量的 Frobenius 范数

W = tf.Variable(tf.random_normal([3072,20],stddev=0.1))
temp = tf.matmul(tf.transpose(W),W)
fro_W = tf.norm(temp, ord ='fro')

这会产生以下错误:

ValueError: 'ord' 必须是受支持的向量范数,来自

我不明白为什么它将我的 2D 张量视为向量而不是矩阵。

我是不是漏掉了什么?

谢谢

来自documentation

The Frobenius norm fro is not defined for vectors

此外,

If axis is None (the default), the input is considered a vector

试试这个:

tf.norm(temp, ord='fro', axis=(0,1))