Search code examples
tensorflowmatrix-inverse

TensorFlow: shape rank 2 in tf.matrix_inverse()


I have a problem when I try the tf.matrix_inverse() method.

I have a Tensor of dimension [17,400,400]. And we can read in the API documentation:

The input is a tensor of shape [..., M, M] whose inner-most 2 dimensions form square matrices.

In my case M=400. And when I try to calculate the 17 inverse matrix:

Out[56]: L
Out[57]: <tf.Tensor 'while_4/Exit_1:0' shape=(17, 400, 400) dtype=float32>
Out[59]: InvL = tf.matrix_inverse(L)
        ValueError: Shape (17, 400, 400) must have rank 2

I understand that L have a shape rank 2, but the method fails. I don't know if I'm doing something wrong. Any help?


Solution

  • The API documentation you are referencing is only for tensorflow release r0.11 or the master version.

    Check your tensorflow version first:

    import tensorflow
    tensorflow.__version__
    

    For release prior to r0.11, as the documentation says here:

    tf.matrix_inverse doc for r0.10

    It doesn't support inverting tensors with rank!=2

    Try update the tensorflow to r0.11 or pull directly from their github master branch