0

I am working with TensorFlow in Python.

I read through the documentation of tf.random.truncated_normal that the input 'shape' gets 1-D tensor or python array, i.e. a vector (according to https://www.tensorflow.org/guide/tensors).

However, with the example I'm using, 'shape' is a 4-D tensor. Or is it considered a vector? Perhaps I have problem with the definition of vectors and tensors?

def weight_variable(shape, name = 'noname'):
  initial = tf.truncated_normal(shape, stddev=0.1)
  return tf.Variable(initial, name = name)

W_conv1 = weight_variable([5, 5, 3, 32], 'W_conv1')
LJNielsenDk
  • 1,414
  • 1
  • 16
  • 32
shoosh_pap
  • 11
  • 2
  • I'm dumb, 'shape' itself is a 1-D tensor, but that does not mean the output tensor is a vector. – shoosh_pap Dec 25 '18 at 19:31
  • Have a look at this answer and the related blog post: https://stackoverflow.com/questions/37085430/tf-shape-get-wrong-shape-in-tensorflow/37085824#37085824 – nessuno Dec 26 '18 at 19:25

1 Answers1

1

So there is a small mistake you are making in your understanding of a Tensor. A Tensor can have different "ranks". A single scalar such as 1 is a Rank 0 Tensor. A list/vector such as [1,2,3,4] is a Rank 1 Tensor. a 2-D Matrix such as [[0,0],[0,0]] is a Rank 2 Tensor and 3D Matrix are Rank 3 Tensors and so on. So the input you have here is a vector or Rank 1 Tensor not a 4-D Tensor.

Here is a nice blog post about this.