猿问

Tensorflow:张量二值化

我想以这样一种方式转换这个数据集,即每个张量都有给定的大小,n并且i当且仅当i原始特征(模 n)中有一个时,这个新张量的索引处的特征设置为 1 。


我希望下面的例子能让事情更清楚


假设我有一个数据集,如:


t = tf.constant([

  [0, 3, 4],

  [12, 2 ,4]])

ds = tf.data.Dataset.from_tensors(t)

我想得到(如果n= 9)


t = tf.constant([

  [1, 0, 0, 1, 1, 0, 0, 0, 0], # index set to 1 are 0, 3 and 4

  [0, 0, 1, 1, 1, 0, 0, 0, 0]]) # index set to 1 are 2, 4, and 12%9 = 3

我知道如何将模应用于张量,但我不知道如何进行其余的转换,谢谢


aluckdog
浏览 573回答 1
1回答
随时随地看视频慕课网APP

相关分类

Python
我要回答