当前位置:网站首页>tf. nn. top_ k()
tf. nn. top_ k()
2022-06-26 05:56:00 【Wanderer001】
Reference resources tf.nn.top_k() - cloud + Community - Tencent cloud
One 、 The function prototype
tf.nn.top_k(
input,
k=1,
sorted=True,
name=None
)To find the largest of the last dimension of the input tensor k A value and its subscript !
If you enter a vector , That is to say rank=1, Find the biggest k The number is in this vector , Then the maximum k A number and the largest one k Subscript of a number . If the input tensor is a higher rank Matrix , Then we just need to find the largest in each line k A digital , And their subscripts . If two elements are the same , So the lower subscript appears first .
Parameters :
- input: Input tensor, It can't be array These ! Either type 1-D, For higher dimensions, the length of the last dimension must be greater than or equal to K
- k:0-D Of int32 Digital tensor of .
- sorted: If sorted=True, So the selected one k Numbers need to be sorted in descending order
- name: optional , This is the name of the operation
return :
- values: That is, the largest of each line k A digital
- indices: The subscript here is the subscript in the last dimension of the input tensor
Two 、 Example
import tensorflow as tf
import numpy as np
# Select the largest first two digits of each line
# The return is the largest k A digital , At the same time, the maximum k Numbers in the subscript of the last dimension
a=tf.constant(np.random.rand(3,4))
b=tf.nn.top_k(a,k=2)
with tf.Session() as sess:
print(sess.run(a))
print(sess.run(b))
Output:
[[0.73731748 0.13455566 0.20236765 0.92909052]
[0.7923021 0.46949081 0.31521194 0.2999236 ]
[0.19102823 0.01301476 0.70615716 0.68501807]]
TopKV2(values=array([[0.92909052, 0.73731748],
[0.7923021 , 0.46949081],
[0.70615716, 0.68501807]]), indices=array([[3, 0],
[0, 1],
[2, 3]], dtype=int32))边栏推荐
猜你喜欢

【群内问题学期汇总】初学者的部分参考问题

Cython入门

421- binary tree (226. reversed binary tree, 101. symmetric binary tree, 104. maximum depth of binary tree, 222. number of nodes of complete binary tree)

Status mode, body can change at will

电商借助小程序技术发力寻找增长突破口

Class and object learning

【C语言】深度剖析数据在内存中的存储

家庭记账程序(第二版 加入了循环)

421-二叉树(226. 翻转二叉树、101. 对称二叉树、104.二叉树的最大深度、222.完全二叉树的节点个数)

Record how to modify the control across threads
随机推荐
About XXX management system (version C)
The difference between overload method and override method
Sql语法中循环的使用
Easy to understand from the IDE, and then talk about the applet IDE
Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast
RIA想法
Force buckle 875 Coco, who likes bananas
Day2- syntax basis and variables
Talk 5 wireless communication
Redis多线程与ACL
Life is so fragile
Consul服务注册与发现
MEF framework learning record
Definition of Halcon hand eye calibration
家庭记账程序(第二版 加入了循环)
numpy.exp()
Describe an experiment of Kali ARP in LAN
【C语言】深度剖析数据在内存中的存储
BOM document
Lesson 4 serial port and clock