1
例如,在[0, 8]
一些应该返回0
,在(8, 16]
回报1
,在(16, 24]
应该返回2
等..如何在TensorFlow中将连续的数字转换为几个类?
然后,如果我有一个张量[2,3,9,18]
,我怎样才能在TensorFlow输出列表[0, 0, 1, 2]
?
谢谢。
编辑:
现在我用tf.case
这个需求
c0 = lambda: tf.constant(0.)
c1 = lambda: tf.constant(1.)
c2 = lambda: tf.constant(2.)
c3 = lambda: tf.constant(3.)
cases = lambda x: {tf.less(x, 9.): c0, tf.less(x, 18.): c1, tf.less(x, 24.): c2}
condition = lambda x: tf.case(cases(x), default=c3, exclusive=False, name='condition')
output = tf.map_fn(lambda x: condition(x), input, name='prediction')
Thk!我使用第一种方法,并使用'tf.map_fn',我不知道有些'API'可以做到这一点。第二种方法对此很有帮助,但实际上这个区域并不统一,可能是'0,3,8,15,16'...... – danche