gpt4 book ai didi

python - tensorflow 2.0 : How to update tensors?

转载 作者:行者123 更新时间:2023-11-28 18:01:12 24 4
gpt4 key购买 nike

在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com