python - TensorFlow 特征值和特征向量

标签 python tensorflow eigenvalue eigenvector

我想在 TensorFlow 中使用特征值,但它使用“tf.self_adjoint_eig”给出了错误的特征值/特征向量

在下面的代码中,我试图恢复原始矩阵,但输出与原始矩阵不同,知道如何修复吗?

`A11 = tf.constant([[1, 3],[1, 1]], dtype=tf.float32)
[e1, W1] = tf.self_adjoint_eig(A11)
e1 = tf.diag(e1)
A11r = tf.matmul(tf.matmul(W1, e1), tf.matrix_inverse(W1))
A11: [[1. 3.]
[1. 1.]]
A11r: [[0.9999999 0.9999999]
[0.9999999 0.9999999]]` 

最佳答案

如果'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)>

Here are what I'm getting as errors, and check to see for 'import tensorflow as tf'

  1. AttributeError: module 'tensortlow' has no attribute 'self_adjoint_eig'
  2. AttributeError: module 'tensorflow' has no attribute 'diag'
  3. AttributeError: module 'tensorflow' has no attribute 'matrix_inverse'

关于python - TensorFlow 特征值和特征向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51535479/

相关文章:

c++ - Armadillo 的 eig_sym 中的线程安全问题

c++ - 2x2 自邻(埃尔米特)矩阵的对角化

python - 如何在Python中基于gram-matrix实现从距离矩阵中查找点的坐标?

python - 如何使用 raw_input 获取汉字

python - 你如何在 python 中将字符串转换为填充的二进制文件?

python - 我们如何在Windows中将模型保存为.pb文件

python - 如何在 TensorFlow Probability 中创建分布数组?

python - tf.nn.conv2D 中的 channel 是什么?

python - github 中私有(private)组织的所有存储库列表

tensorflow - TPU上训练模型后单张图像的预测值