当前位置:网站首页>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)
边栏推荐
- [hdu 2096] Xiaoming a+b
- MySQL storage engine
- ZABBIX 5.0 - LNMP environment compilation and installation
- Which domestic cloud management platform manufacturer is good in 2022? Why?
- How to clear floating?
- Introduction to GNN
- GPS數據格式轉換[通俗易懂]
- ZABBIX customized monitoring disk IO performance
- Halcon template matching actual code (I)
- ZABBIX monitors mongodb (template and deployment operations)
猜你喜欢

One article tells the latest and complete learning materials of flutter

Why learn harmonyos and how to get started quickly?

Linux安装部署LAMP(Apache+MySQL+PHP)

Select drop-down box realizes three-level linkage of provinces and cities in China

Summary of C language learning problems (VS)

Redis highly available sentinel cluster

mysql拆分字符串做条件查询

MySQL index - extended data

Get data from the database when using JMeter for database assertion

MySQL transaction
随机推荐
Swift - add navigation bar
[HDU 2096] 小明A+B
Master-slave mode of redis cluster
II. Data type
[untitled]
ZABBIX 5.0 - LNMP environment compilation and installation
Xi IO flow
MySQL storage engine
GPS data format conversion [easy to understand]
PXE startup configuration and principle
What is the difference between canvas and SVG?
Matlab struct function (structure array)
MySQL log module of InnoDB engine
Seven polymorphisms
SENT协议译码的深入探讨
ZABBIX monitors mongodb (template and deployment operations)
PIP command reports an error pip is configured with locations that requires tls/ssl problems
只是巧合?苹果 iOS16 的神秘技术竟然与中国企业 5 年前产品一致!
Constructing expression binary tree with prefix expression
[superhard core] is the core technology of redis