Tensorflow.js tf.Variable class .assign() method
The assign() is the method available in the Variable class which is used to assign the new tf.Tensor to the variable. The new value must have the same shape and dtype as the old Variable value.
- newValue: It’s an object of type tf.Tensor. This new value gets assigned to the variable.
Return Value: It returns void.
Example 1: This example first creates a new tf.Variable object with initial value then assign this variable a new value with same shape and dtype as an initial value.
dtype: float32 shape: 1,3 Tensor [[1, 2, 3],] Tensor [[5, 8, 10],]
Example 2: This example first creates a new tf.Variable object with initial value then it tries to assign this variable a new value with different shape as the initial value. This will give an error.
dtype: float32 shape: 2,2 Tensor [[1, 2], [3, 4]] Tensor [[5 , 6 ], [10, 11]]