当前位置:网站首页>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)
边栏推荐
- Complete activity switching according to sliding
- ABAP table lookup program
- byte2String、string2Byte
- 语义分割实验:Unet网络/MSRC2数据集
- ZABBIX agent2 installation
- GPS数据格式转换[通俗易懂]
- Solve the problem of cache and database double write data consistency
- Video networkState 属性
- byte2String、string2Byte
- Semantic segmentation experiment: UNET network /msrc2 dataset
猜你喜欢

Read and understand the rendering mechanism and principle of flutter's three trees

What is digital existence? Digital transformation starts with digital existence

Intern position selection and simplified career development planning in Internet companies

How can beginners learn flutter efficiently?

Implementing Yang Hui triangle with cyclic queue C language
![[untitled]](/img/56/6a9a4bcab6503872942fff7a365def.jpg)
[untitled]

Mmclassification training custom data

The evolution of mobile cross platform technology

MySQL splits strings for conditional queries

Why learn harmonyos and how to get started quickly?
随机推荐
MySQL regular expression
ZABBIX monitors mongodb (template and deployment operations)
Hiengine: comparable to the local cloud native memory database engine
[figure neural network] GNN from entry to mastery
Conversion du format de données GPS [facile à comprendre]
嵌入式软件架构设计-消息交互
A guide to threaded and asynchronous UI development in the "quick start fluent Development Series tutorials"
Learn memory management of JVM 01 - first memory
Just a coincidence? The mysterious technology of apple ios16 is actually the same as that of Chinese enterprises five years ago!
Understand kotlin from the perspective of an architect
Understand redis persistence mechanism in one article
Yum only downloads the RPM package of the software to the specified directory without installing it
报错ModuleNotFoundError: No module named ‘cv2.aruco‘
Intern position selection and simplified career development planning in Internet companies
Cypher syntax of neo4j graph database
PXE startup configuration and principle
struct MySQL
Pytoch uses torchnet Classerrormeter in meter
Xi IO flow
16 channel water lamp experiment based on Proteus (assembly language)