1

To say, i have a tensor matrix:

matrix=tf.convert_to_tensor([[1,1,1,1],[0,0,0,0]],dtype=tf.float32)

and i get the shape of matrix using tf.shape(matrix), the result is

<tf.Tensor 'Shape_2:0' shape=(2,) dtype=int32>

however using print(matrix), i get the result:

<tf.Tensor 'Const_257:0' shape=(2, 4) dtype=float32>.

Why they are not the same. I'm new with tensorflow, can anybody explain it?

thanks a lot.

gdelab
  • 6,124
  • 2
  • 26
  • 59
Bin
  • 25
  • 4
  • 1
    Seems like you somehow messed up the formatting of your question. Anyway, I guess [this](https://stackoverflow.com/a/37096395/1658772) answer will answer your question. – chrert Jul 10 '17 at 13:30

1 Answers1

2

The method tf.shape() returns a new tensor containing the shape of the input tensor. The returned tensor is completely different than the input tensor.

>>> import tensorflow as tf
>>> matrix = tf.convert_to_tensor([[1,1,1,1],[0,0,0,0]],dtype=tf.float32)
>>> matrix
<tf.Tensor 'Const_5:0' shape=(2, 4) dtype=float32>
>>> matrix.get_shape()
TensorShape([Dimension(2), Dimension(4)])
>>> shape_tensor = tf.shape(matrix)
>>> shape_tensor
<tf.Tensor 'Shape_3:0' shape=(2,) dtype=int32>
Memduh
  • 836
  • 8
  • 18