当前位置:网站首页>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))边栏推荐
猜你喜欢

How to associate wechat applet QR code to realize two code aggregation

Using Jenkins to perform testng+selenium+jsup automated tests and generate extendreport test reports
Posting - don't get lost in the ocean of Technology

【 langage c】 stockage des données d'analyse approfondie en mémoire

Status mode, body can change at will

类和对象的学习

Navicat如何将当前连接信息复用另一台电脑

家庭记账程序(第一版)

MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications

Redis多线程与ACL
随机推荐
旧情书
Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast
Status mode, body can change at will
组合模式、透明方式和安全方式
Sql语法中循环的使用
新的征程
Definition of Halcon hand eye calibration
力扣 875. 爱吃香蕉的珂珂
Pytorch (network model training)
1212312321
Written before father's Day
家庭记账程序(第二版 加入了循环)
[C language] deep analysis of data storage in memory
The most refined language interprets the event dispatcher (also known as the event scheduler)
Kolla ansible deploy openstack Yoga version
one billion two hundred and twelve million three hundred and twelve thousand three hundred and twenty-one
冒泡排序(Bubble Sort)
Gram matrix
kolla-ansible部署openstack yoga版本
Day4 branch and loop