python - tensorflow 2.0 : How to update tensors?

标签 python tensorflow tensorflow2.0

在 TensorFlow 1.x 中,要更新张量,我会使用 tf.scatter_update,只更新张量的相关部分。

我们如何在 TF 2.0 中做同样的事情?

最佳答案

您可以使用 tf.tensor_scatter_nd_update() :

import tensorflow as tf
import numpy as np 

tensor = tf.convert_to_tensor(np.ones((2, 2)), dtype=tf.float32)
indices = tf.constant([[0, 0]])
updates = tf.constant([0.0])

tf.tensor_scatter_nd_update(tensor, indices, updates).numpy()
# array([[0., 1.],
#        [1., 1.]], dtype=float32)

关于python - tensorflow 2.0 : How to update tensors?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55652981/

相关文章:

python - TF2.0 Data API 从每个类标签中获取 n_i 个样本

python - GBQ | python : How can I retrieve data types of all the columns in a table?

machine-learning - 输入队列没有响应 TensorFlow 程序挂起

TensorFlow 2 : RuntimeError: Cannot use a constraint function on a sparse variable

python - TF2.0中如何将tf.data.Dataset类型的数据切片到一定长度?

python - 在 Keras 中加载权重后添加 DropOut

python - libnotify 的 Action 回调不起作用

python - 如何从python中的文本中获取字体大小

Python:将二维二进制值数组打包到 UINT64 数组中的最快方法

python - 参数无效错误:Load a (frozen) Tensorflow model into memory (While testing the model on local machine)