How can I change the shape of a variable in TensorFlow?

前端 未结 6 557
醉梦人生
醉梦人生 2020-12-03 07:21

TensorFlow tutorial says that at creation time we need to specify the shape of tensors. That shape automatically becomes the shape of the tensor. It also says that TensorF

6条回答
  •  盖世英雄少女心
    2020-12-03 07:33

    As said by Mayou36, you can now change the variable shape after it was first declared. Here is a working example:

    v = tf.Variable([1], shape=tf.TensorShape(None), dtype=tf.int32) 
    tf.print(v)
    v.assign([1, 1, 1])
    tf.print(v)
    

    And this outputs:

    [1]
    [1 1 1]
    

提交回复
热议问题