Skip to content

Tensor[slice].assign() not working #653

Closed

Description

@Banyc

Issue

When running the code below:

Tensor x = tf.Variable(tf.ones((2, 2)));
Console.WriteLine(x);

// https://stackoverflow.com/a/43139565/9920172
x["0", "0"].assign(tf.constant(2));
Console.WriteLine(x);
Tensor y = x["0", "0"].assign(tf.constant(2));
Console.WriteLine(y);

An error occurs:

An unhandled exception of type 'System.ArgumentException' occurred in TensorFlow.NET.dll: 'Dimensions { and { are not compatible'

In Addition

This operation is mentioned in Tensorflow official documentation. Here is the link: https://www.tensorflow.org/api_docs/python/tf/Variable#__getitem__.

import tensorflow as tf
A = tf.Variable([[1,2,3], [4,5,6], [7,8,9]], dtype=tf.float32)
with tf.compat.v1.Session() as sess:
  sess.run(tf.compat.v1.global_variables_initializer())
  print(sess.run(A[:2, :2]))  # => [[1,2], [4,5]]

  op = A[:2,:2].assign(22. * tf.ones((2, 2)))
  print(sess.run(op))  # => [[22, 22, 3], [22, 22, 6], [7,8,9]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions