如何将此代码转换为python [英] How did convert this code to the python

查看:95
本文介绍了如何将此代码转换为python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void srcn(short int** pd,int* nse,int il,int jl)
{
	int i,j,k,l;
	double std,avg,temp;
	for(i=rn;i<il-rn;i++){
		for(j=rn;j<jl-rn;j++){
			avg=0;
			temp=0;
			std=0;
			for(k=-rn;k<=rn;k++){
				for(l=-rn;l<=rn;l++){
					avg+=(double)pd[i+k][j+l];
				}
			}
			avg=avg/((double)sn*sn);
			for(k=-rn;k<=rn;k++){
				for(l=-rn;l<=rn;l++){
				temp+=((double)pd[i+k][j+l]-avg)*((double)pd[i+k][j+l]-avg);
				}
			}
			std=pow(temp/((double)sn*sn),0.5);
			if(std<c*drt){
				nse[0]++;
			}
			else{
				nse[1]++;
			}
		}
	}
	
}





我尝试了什么:



我想用Python转换这段代码。



What I have tried:

I want to convert this code with Python.

推荐答案

Quote:

想要用Python转换这段代码。

want to convert this code with Python.

那很好....你最好先开始吧。你有两个选择(可能更多)



1)'transliterate' - 查看c代码,将其转换为最接近的Python代码&写一下



2)分析c例程的'功能',并在Python中从头开始编写该功能 - Python中可能有更快的构造使其更容易



显然测试,测试,测试,大量的值,以确保你最终得到你想要的东西



玩得开心

thats nice .... you'd better get started then. You have two options (maybe more)

1) 'transliterate' - look at the c code, translate it to the closest Python code & write that

2) Analyse the 'functionality' of the c routine, and write that functionality from scratch in Python - there may be quicker constructs in Python that make it easier

obviously test, test, test, a large number of values to make sure what you end up with does what you want

Have fun


这篇关于如何将此代码转换为python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆