【发布时间】:2022-08-16 04:10:19
【问题描述】:
我有一个 @tf.function 装饰函数。在函数内部,我想从分布中提取并多次计算某个值(让我们将此过程称为 f(x))。
如何在 TensorFlow 2.0 中做到这一点?我不能使用 numpy 数组,因为我想使用 @tf.function 装饰器。
一个 numpy 实现看起来像:
reps = 4
store = np.zeros((n, reps))
for i in range(reps):
store[:, i] = f(x) #f(x) is shape (n,)
然后目标是计算store 的行均值。
这应该很容易,但我无法弄清楚如何去做!
标签: python tensorflow tensorflow2.0 immutability tf.keras