当前位置:网站首页>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)
边栏推荐
- Take you two minutes to quickly master the route and navigation of flutter
- How to clear floating?
- PXE startup configuration and principle
- Understand kotlin from the perspective of an architect
- The evolution of mobile cross platform technology
- Master-slave mode of redis cluster
- Design of music box based on assembly language
- ZABBIX agent2 monitors mongodb templates and configuration operations
- End to end neural network
- NPM install reports an error
猜你喜欢

Tabbar configuration at the bottom of wechat applet

Get the variable address of structure member in C language

Yum only downloads the RPM package of the software to the specified directory without installing it

Migrate data from Mysql to neo4j database

Interviewer: is acid fully guaranteed for redis transactions?

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

How to clear floating?

Learn memory management of JVM 01 - first memory

ZABBIX customized monitoring disk IO performance

C language structure is initialized as a function parameter
随机推荐
MySQL basic operation -dql
mmclassification 训练自定义数据
MySQL data table operation DDL & data type
Redis highly available slice cluster
Hexadecimal conversion summary
Take you hand in hand to develop a service monitoring component
Get all stock data of big a
Understand redis persistence mechanism in one article
One article tells the latest and complete learning materials of flutter
Learn JVM garbage collection 02 - a brief introduction to the reference and recycling method area
Uniapp + unicloud + Unipay realize wechat applet payment function
SENT协议译码的深入探讨
信息服务器怎么恢复,服务器数据恢复怎么弄[通俗易懂]
Is investment and finance suitable for girls? What financial products can girls buy?
Which domestic cloud management platform manufacturer is good in 2022? Why?
Redis highly available sentinel mechanism
Get the variable address of structure member in C language
Learning items
Learn the garbage collector of JVM -- a brief introduction to Shenandoah collector
Average lookup length when hash table lookup fails