Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tf.unique无重复索引_Python_Tensorflow_Deep Learning_Unique_Tensor - Fatal编程技术网

Python tf.unique无重复索引

Python tf.unique无重复索引,python,tensorflow,deep-learning,unique,tensor,Python,Tensorflow,Deep Learning,Unique,Tensor,我的输入是一个张量,例如[8,8,8,2,2,3,1,1,8,8]。我的输出应该是一个张量,它引用了这个张量的每一段,看起来像这样:[0,0,0,1,1,2,3,3,4,4]。我必须用张量流来计算 tf.unique([8,8,8,2,2,3,1,1,8,8])计算一个张量[0,0,0,1,1,2,3,3,0,0],该张量的末尾由4改为0 有人知道如何解决这个问题吗?您想要执行的操作实际上与tf.unique没有多大关系。实现这一结果的一种方法是: 将tensorflow导入为tf def识别_

我的输入是一个张量,例如
[8,8,8,2,2,3,1,1,8,8]
。我的输出应该是一个张量,它引用了这个张量的每一段,看起来像这样:
[0,0,0,1,1,2,3,3,4,4]
。我必须用张量流来计算

tf.unique([8,8,8,2,2,3,1,1,8,8])
计算一个张量
[0,0,0,1,1,2,3,3,0,0]
,该张量的末尾由4改为0


有人知道如何解决这个问题吗?

您想要执行的操作实际上与
tf.unique
没有多大关系。实现这一结果的一种方法是:

将tensorflow导入为tf
def识别_块(a):
neq=tf.不相等(a[1:],a[:-1])
c=tf.cumsum(tf.dtypes.cast(neq,tf.int32))
返回tf.concat([[0],c],轴=0)
a=tf.常数([8,8,8,2,2,3,1,1,8,8])
b=识别块(a)
打印(b.numpy())
# [0 0 0 1 1 2 3 3 4 4]

您想要执行的操作实际上与
tf.unique
没有太大关系。实现这一结果的一种方法是:

将tensorflow导入为tf
def识别_块(a):
neq=tf.不相等(a[1:],a[:-1])
c=tf.cumsum(tf.dtypes.cast(neq,tf.int32))
返回tf.concat([[0],c],轴=0)
a=tf.常数([8,8,8,2,2,3,1,1,8,8])
b=识别块(a)
打印(b.numpy())
# [0 0 0 1 1 2 3 3 4 4]