当前位置:网站首页>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))边栏推荐
- Thinking about bad money expelling good money
- The difference between abstract and interface interface
- How to use the tablet as the second extended screen of the PC
- Implementation of third-party wechat authorized login for applet
- Introduction to lcm32f037 series of MCU chip for motor
- 劣币驱逐良币的思考
- ES6的搭配环境
- SSH keygen specifies the path
- Customize WebService as a proxy to solve the problem of Silverlight calling WebService across domains
- numpy.exp()
猜你喜欢

Class and object learning

Implementation of third-party wechat authorized login for applet

Redis底层数据结构

Kolla ansible deploy openstack Yoga version

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

适配器模式
![[C language] deep analysis of data storage in memory](/img/2e/ff0b5326d796b9436f4a10c10cfe22.png)
[C language] deep analysis of data storage in memory

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)

Selective Search for Object Recognition 论文笔记【图片目标分割】

E-commerce seeks growth breakthrough with the help of small program technology
随机推荐
Status mode, body can change at will
Combined mode, transparent mode and secure mode
How to use the tablet as the second extended screen of the PC
Prototype mode, Baa Baa
5 minutes to learn regular expressions
Machine learning 07: Interpretation of PCA and its sklearn source code
Func < T, tresult > Commission - learning record
【C語言】深度剖析數據在內存中的存儲
Factory method pattern, abstract factory pattern
Household accounting procedures (First Edition)
机器学习 07:PCA 及其 sklearn 源码解读
5分钟包你学会正则表达式
Bingc (inheritance)
E-commerce seeks growth breakthrough with the help of small program technology
Summary of JVM interview focus (II) -- garbage collector (GC) and memory allocation strategy
bingc(继承)
Adapter mode
状态模式,身随心变
Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast
Operator priority, associativity, and whether to control the evaluation order [detailed explanation]