当前位置:网站首页>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)
边栏推荐
- Deep discussion on the decoding of sent protocol
- 7月华清学习-1
- Conversion du format de données GPS [facile à comprendre]
- Learning JVM garbage collection 06 - memory set and card table (hotspot)
- Intern position selection and simplified career development planning in Internet companies
- Master-slave mode of redis cluster
- IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
- 强化学习-学习笔记3 | 策略学习
- Clear neo4j database data
- Understanding the architecture type of mobile CPU
猜你喜欢
Migrate data from Mysql to neo4j database
Matlab boundarymask function (find the boundary of the divided area)
[superhard core] is the core technology of redis
About cache exceptions: solutions for cache avalanche, breakdown, and penetration
Redis highly available sentinel cluster
Master the new features of fluent 2.10
Solve the problem of cache and database double write data consistency
Matlab struct function (structure array)
Flutter2 heavy release supports web and desktop applications
July Huaqing learning-1
随机推荐
The survey shows that traditional data security tools cannot resist blackmail software attacks in 60% of cases
嵌入式软件架构设计-消息交互
Redis's memory elimination mechanism, read this article is enough.
PIP command reports an error pip is configured with locations that requires tls/ssl problems
Semantic segmentation experiment: UNET network /msrc2 dataset
byte2String、string2Byte
Select drop-down box realizes three-level linkage of provinces and cities in China
Solve the error 1045 of Navicat creating local connection -access denied for user [email protected] (using password
Principle and performance analysis of lepton lossless compression
MySQL splits strings for conditional queries
NPM install reports an error
报错ModuleNotFoundError: No module named ‘cv2.aruco‘
Matlab struct function (structure array)
byte2String、string2Byte
End to end neural network
MySQL function
MySQL data table operation DDL & data type
Simple production of wechat applet cloud development authorization login
Interviewer: is acid fully guaranteed for redis transactions?
Solution to order timeout unpaid