当前位置:网站首页>Code speed optimization
Code speed optimization
2022-07-29 03:23:00 【smiling0927】
Record a section of the same function , Small pieces of code with vastly different speeds :
I wrote it , Running speed : The bearer of the tortoise world !!!
zero = torch.zeros_like (d)
d_nonoise = torch.zeros_like (d)
for i in range (zero.shape[0]):
for j in range (zero.shape[1]):
d_nonoise[i][j] = torch.where (d[i][j] < (d[i][j].mean () + 3 * d[i][j].std ()), d[i][j], zero[i][j])
d_nonoise[i][j] = torch.where (d[i][j] > (d[i][j].mean () - 3 * d[i][j].std ()), d[i][j], zero[i][j])
return dCode after consultation : The shoulder in the rabbit !
d_mean = d.view (d.shape[0], d.shape[1], -1).mean (dim=-1, keepdim=True).unsqueeze (dim=-1).repeat (1, 1,d.shape[2],d.shape[3])
d_std = d.view (d.shape[0], d.shape[1], -1).std (dim=-1, keepdim=True).unsqueeze (dim=-1).repeat (1, 1,d.shape[2],d.shape[3])
zero = torch.zeros (size=(1,), device=d.device, dtype=d.dtype)
d_nonoise = torch.where ((d < (d_mean + 3 * d_std)) & (d > (d_mean - 3 * d_std)), d, zero)
d = d_nonoise
return dJust take this as a warning : Write good code , Write the code ! Stop making garbage !
边栏推荐
- makefile详解
- Redis之sentinel哨兵集群怎么部署
- Alibaba Sentinel - 工作流程及原理解析
- Calculation of array serial number of force deduction questions (daily question 7/28)
- Web uploader cannot upload multiple files
- Asynchronous callback future mode of concurrent mode
- STC MCU drive 1.8 'TFT SPI screen demonstration example (including data package)
- 4000 多字学懂弄通 js 中 this 指向问题,顺便手写实现 call、apply 和 bind
- Example analysis of while, repeat and loop loops in MySQL process control
- How close can QA be to business code Direct exposure of defects through codediff
猜你喜欢

力扣刷题之数组序号计算(每日一题7/28)

12_ UE4 advanced_ Change a more beautiful character model

What if MySQL forgets the password

Unity game special effects

STC单片机驱动1.8‘TFT SPI屏幕演示示例(含资料包)

Bingbing learning notes: operator overloading -- implementation of date class

Does domestic ERP have a chance to beat sap?

Detailed steps for installing MySQL 8.0 under Linux

MYCAT read / write separation configuration

Digital image processing Chapter 10 - image segmentation
随机推荐
Object转String的几种方法
How does DataGrid export and recover the entire database data, using a single SQL file
How to realize shortcut keys for interface scaling by vscade
How dare you write a resume that is proficient in concurrent programming? Why do you use a two-way linked list in AQS?
Score addition and subtraction of force deduction and brushing questions (one question per day 7/27)
Introduction and advanced level of MySQL (12)
C traps and defects Chapter 2 syntax "traps" 2.6 problems caused by "hanging" else
A simple and general method to obtain the size of function stack space
Pp-yoloe details
Leetcode 1331 array sequence number conversion [map] the leetcode path of heroding
Introduction to JVM foundation I (memory structure)
Division and description of military technical documents
Multiline text omission
Typescript学习(一)
2 neural network toolbox NN
3.1 common neural network layer (I) image correlation layer
Learn exkmp again (exkmp template)
带你来浅聊一下,单商户功能模块汇总
[technology 1]
原理知识用得上