我可以使用tf.arg_max
选择矩阵中的最大索引,
在tensorflow
中是否有一个函数,用于在前n中随机选择索引
test = np.array([
[1, 2, 3],
[2, 3, 4],
[5, 4, 3],
[8, 7, 2]])
argmax0 = tf.arg_max(test, 0)
# argmax0 = [3, 3, 1]
我需要一个函数为每个数组随机选择前2名中的索引。 例如: 第一个colmuns[1,2,5,8],top2是[5,8],只需从[5,8]中随机选择一个即可。 所以最终答案可能是[3,2,0],[2,2,0],[3,3,1],[3,2,0]或更多
您可以使用.argsort方法,然后从该方法中获取最前面的N
获取topk值:
洗牌每行中的值:
选择每个无序行的第一行:
复制/可复制代码:
相关问题 更多 >
编程相关推荐