如果'tf.self_adjoint_eig'不是必须的,你可以这样做:
A11 = tf.constant([[1., 3.],[1., 1.]], dtype=tf.float32)
[e1, W1] = tf.linalg.eig(A11)
e1 = tf.linalg.diag(e1)
A11r = tf.matmul(tf.matmul(W1, e1), tf.linalg.inv(W1))
A11: [[1. 3.]
[1. 1.]]
A11r: [[0.9999999 0.9999999]
[0.9999999 0.9999999]]
尝试使用 tf.linalg.function_name()
这是与你的结果相比的结果。
Input: A11
Output: <tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[1., 3.],
[1., 1.]], dtype=float32)>
Input: A11r
Output: <tf.Tensor: shape=(2, 2), dtype=complex64, numpy=
array([[1.0000001+0.j, 3.0000005+0.j],
[1. +0.j, 1. +0.j]], dtype=complex64)>
以下是我遇到的错误,请检查是否有“import tensorflow as tf”:
- AttributeError:模块“tensortlow”没有属性“self_adjoint_eig”
- AttributeError:模块“tensorflow”没有属性“diag”
- AttributeError:模块“tensorflow”没有属性“matrix_inverse”
A11
矩阵不是自伴矩阵,因此你不应该使用tf.self_adjoint_eig
。 - djdtf.self_adjoint_eig
仅使用输入的下三角部分,因此它会将您的输入矩阵视为tf.constant([[1, 1],[1, 1]], dtype=tf.float32)
处理。最终结果也与此一致。 - djd