当前位置:网站首页>Pytoch counts the number of the same elements in the tensor
Pytoch counts the number of the same elements in the tensor
2022-07-05 12:27:00 【Dongcheng West que】
import torch
class_dic={0:"Benign",1:"In Situ",2:"Invasive",3:"Normal"}
results={"Benign":0,"In Situ":0,"Invasive":0,"Normal":0}
c=torch.tensor([1, 1, 1, 1, 3, 2, 1, 1, 3, 3, 1, 2])
print(c)
#tensor Turn first numpy Re turn list
cc=c.numpy().tolist()
dict = {}
for key in cc:
dict[key] = dict.get(key, 0) + 1
# Get the dictionary dict={1: 7, 3: 3, 2: 2}
results[class_dic[max(dict,key=dict.get)]] = results.get(class_dic[max(dict,key=dict.get)], 0) + 1
# What kind of calculation does it belong to results={'Benign': 0, 'In Situ': 1, 'Invasive': 0, 'Normal': 0}
print(dict)
print(results)
边栏推荐
- Check the debug port information in rancher and do idea remote JVM debug
- MySQL stored procedure
- Swift - add navigation bar
- PXE startup configuration and principle
- How to clear floating?
- 你做自动化测试为什么总是失败?
- Why learn harmonyos and how to get started quickly?
- Is investment and finance suitable for girls? What financial products can girls buy?
- GPS数据格式转换[通俗易懂]
- POJ-2499 Binary Tree
猜你喜欢
MySQL index - extended data
Redis highly available sentinel cluster
Detailed steps for upgrading window mysql5.5 to 5.7.36
Interviewer: is acid fully guaranteed for redis transactions?
强化学习-学习笔记3 | 策略学习
Get data from the database when using JMeter for database assertion
Redis highly available sentinel mechanism
Mmclassification training custom data
Linux安装部署LAMP(Apache+MySQL+PHP)
What is digital existence? Digital transformation starts with digital existence
随机推荐
byte2String、string2Byte
C language structure is initialized as a function parameter
自动化测试生命周期
MySQL splits strings for conditional queries
Pytoch uses torchnet Classerrormeter in meter
Third party payment interface design
ABAP table lookup program
Cypher syntax of neo4j graph database
Error modulenotfounderror: no module named 'cv2 aruco‘
MySQL multi table operation
Leetcode-1. Sum of two numbers (Application of hash table)
Two minutes will take you to quickly master the project structure, resources, dependencies and localization of flutter
Reinforcement learning - learning notes 3 | strategic learning
IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
Redis highly available sentinel cluster
Complete activity switching according to sliding
Redis highly available sentinel mechanism
Open3d mesh (surface) coloring
GPS數據格式轉換[通俗易懂]
July Huaqing learning-1