1

I need to assign zero to Tensorflow variable as seen below. Is it possible to do that? What should I do?

layer = tf.nn.sigmoid(tf.add(tf.matmul(x, h), b))
layer[0] = 0

In the example above, I want to set zero value to the first index of the variable calculated by multiplying x matrix and h vector.

Turkdogan Tasdelen
  • 898
  • 1
  • 11
  • 25

1 Answers1

2

You can't assign it directly but you can use .assign() operation to make it happen, here is the documentation. Also after you assign you have to run the operation using .run() or .eval(). In my opinion, this code should work:

layerOp = layer[0].assign(0)
sess.run(layerOp) 

Please find this post for reference.

Community
  • 1
  • 1
PseudoAj
  • 5,234
  • 2
  • 17
  • 37
  • 2
    Just to clarify: `layer` in the above is a `tf.Tensor` rather than a `tf.Variable`, so the `assign()` method isn't defined on it. The easiest way to achieve the desired outcome is using `tf.slice()` and `tf.concat()` to build the desired result. – mrry May 24 '16 at 01:23