当前位置:网站首页>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)
边栏推荐
- 【ijkplayer】when i compile file “compile-ffmpeg.sh“ ,it show error “No such file or directory“.
- Want to ask, how to choose a securities firm? Is it safe to open an account online?
- MySQL index - extended data
- MySQL trigger
- GPS数据格式转换[通俗易懂]
- What is digital existence? Digital transformation starts with digital existence
- PXE启动配置及原理
- Tabbar configuration at the bottom of wechat applet
- 一款新型的智能家居WiFi选择方案——SimpleWiFi在无线智能家居中的应用
- Why do you always fail in automated tests?
猜你喜欢
Redis highly available slice cluster
Four operations and derivative operations of MATLAB polynomials
The evolution of mobile cross platform technology
Mmclassification training custom data
Check the debug port information in rancher and do idea remote JVM debug
强化学习-学习笔记3 | 策略学习
Constructing expression binary tree with prefix expression
Embedded software architecture design - message interaction
Why learn harmonyos and how to get started quickly?
mysql拆分字符串做条件查询
随机推荐
Migrate data from Mysql to neo4j database
想问问,如何选择券商?在线开户是很安全么?
Tabbar configuration at the bottom of wechat applet
Correct opening method of redis distributed lock
Open3d mesh (surface) coloring
SENT协议译码的深入探讨
MySQL stored procedure
GPS data format conversion [easy to understand]
mysql拆分字符串做条件查询
Learn JVM garbage collection 05 - root node enumeration, security points, and security zones (hotspot)
Video networkstate property
ZABBIX monitors mongodb templates and configuration operations
Instance + source code = see through 128 traps
One article tells the latest and complete learning materials of flutter
【ijkplayer】when i compile file “compile-ffmpeg.sh“ ,it show error “No such file or directory“.
Master the new features of fluent 2.10
信息服务器怎么恢复,服务器数据恢复怎么弄[通俗易懂]
Automated test lifecycle
Understanding the architecture type of mobile CPU
MySQL basic operation -dql