Numpy 索引分配的 Tensorflow 等效项 [英] Tensorflow equivalent for Numpy indexed assignment

查看:22
本文介绍了Numpy 索引分配的 Tensorflow 等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Tensorflow 中的伪 (*) 等价物是什么?

What is the pseudo(*)-equivalent in Tensorflow for this?

array[array < 50] = 0 # numpy

我想应该是这样的:

array = tf.something(array, ...) # or array2 = ...
# OR
array = array.something(...) # or array2 = ...

(*) 我不会假装保持数组可变,也不会因为我是张量而立即执行.

(*) I do not pretend to keep the array mutable neither it to be executed at the moment as I would be a tensor.

也许另一种提问方式是:将依赖于 tf.less() 的 tf.cond() 条件张量数组应用于数字数组的代码是什么?

Maybe another way to ask this is: How would be the code for applying an array of conditional tensors of tf.cond() depending on tf.less() to an array of numbers?

推荐答案

你可以做

tf.select(array < 50, tf.zeros_like(array), array)

这将返回一个表达式,它与 arrayarray[array <;50] = 0.如果 array 是一个 TensorFlow 变量,你可以使用 tf.assign 将上述表达式赋值给 array.

which will return an expression equivalent to what array will contain after array[array < 50] = 0. If array was a TensorFlow variable, you can use tf.assign to assign the above expression to array.

这篇关于Numpy 索引分配的 Tensorflow 等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆