我有这个代码片段:
import tensorflow as tf
import numpy as np
# batch x time x events x dim
batch = 2
time = 3
events = 4
tensor = np.random.rand(batch, time, events)
tensor[0][0][2] = 0
tensor[0][0][3] = 0
tensor[0][1][3] = 0
tensor[0][2][1] = 0
tensor[0][2][2] = 0
tensor[0][2][3] = 0
tensor[1][0][3] = 0
def cum_sum(prev, cur):
non_zeros = tf.equal(cur, 0.)
tf.Print(non_zeros, [non_zeros], "message ")
tf.Print(cur, [cur])
return cur
elems = tf.constant([1,2,3],dtype=tf.int64)
#alternates = tf.map_fn(lambda x: (x, 2*x, -x), elems, dtype=(tf.int64, tf.int64, …Run Code Online (Sandbox Code Playgroud)