tensorflow如何计算数组的秩

问题描述 投票:0回答:1

如何获得数组的排名,例如pandas.DataFrame.rank()

例如,对于此数组:

a = tf.constant([0, 2, 3, 3])

我期望的结果是:

([0, 1, 2, 2])
tensorflow
1个回答
0
投票

这是我找到的答案:

__, rank = tf.unique(a)
print(rank)
<tf.Tensor: shape=(4,), dtype=int32, numpy=array([0, 1, 2, 2], dtype=int32)>
© www.soinside.com 2019 - 2024. All rights reserved.