Search code examples
pythonnumpytensorfloweigenvalue

Why the eigenvalue output is different for tensorflow and numpy?


I tried to calculate Eigenvalues for matrix using both numpy and tensorflow but I am getting different eigenvalues for each implementation. Below are the details

A=([1,2,3],[1,2,3],[1,2,3]) 

EigenValues of A with numpy are [0,6,0]

EigenValues of A with tensorflow are [ 0.30797836, 0.64310414, 5.04891825]

I used tf.self_adjoint_eig for tensorflow implementation and numpy.linalg.eig for numpy implementation.


Solution

  • From description of the function: https://www.tensorflow.org/versions/master/api_docs/python/math_ops.html#self_adjoint_eig

    Calculates the Eigen Decomposition of a square Self-Adjoint matrix.

    Only the lower-triangular part of the input will be used in this case. The upper-triangular part will not be read.

    Therefore TensorFlow's self_adjoint_eig on your matrix is equivalent to numpy's eig of the following matrix

    ({1,1,1},{1,2,2},{1,2,3})