您好,我有以下函数会产生越界错误:
import numpy as np
import pylab as plt
import scipy
import math
import sympy as sy
T = sy.Symbol('T')
rho = sy.Symbol('rho')
g_T = [1,T,T**2,T*sy.log(T),T**2*sy.log(T)]
g_rho = [1,rho,rho**2,rho*sy.log(rho),rho**2*sy.log(rho)]
g_T_np = np.asarray(g_T)
g_rho_np = np.asarray(g_rho)
c = np.loadtxt("c_test.txt")
def F(T,rho):
ret = 0
for n in xrange(1,5):
for m in xrange(1,6):
inner= c[n,m]*g_T_np*g_rho_np
ret += inner
return ret
print F(T,rho)
Run Code Online (Sandbox Code Playgroud)
其中 .txt 文件如下所示:
-0.529586 -0.000208559 -3.36563E-09 2.29441E-05
2.22722E-06 -0.00014526 -2.48888E-09 1.89488E-05
-6.26662E-05 0.000421028 6.17407E-09 -5.14488E-05
0.09977346 -0.000622051 -8.56485E-09 7.49956E-05
-0.01437627 …Run Code Online (Sandbox Code Playgroud) 在 C# 7 中,我们可以这样做:
byte.TryParse(p.Value, out _)
Run Code Online (Sandbox Code Playgroud)
或者像这样
byte.TryParse(p.Value, out var _)
Run Code Online (Sandbox Code Playgroud)
有什么区别吗?
我有以下静态 C# 方法
public static bool TryParse (string s, out double result)
Run Code Online (Sandbox Code Playgroud)
我想使用 Python NET 包从 Python 调用它。
import clr
from System import Double
r0 = Double.IsNaN(12.3) # works
r1, d1 = Double.TryParse("12.3") # fails! TypeError: No method matches given arguments. This works in IronPython.
d2 = 0.0
r2, d2 = Double.TryParse("12.3", d2) # fails! TypeError: No method matches given arguments
Run Code Online (Sandbox Code Playgroud)
任何的想法?
更新
我找到了以下答案,请参阅/sf/answers/1372024461/。
使用 PythonNet 的 CPython 基本上做同样的事情。处理参数的简单方法是不传递它们并接受它们作为额外的返回值,对于 ref 参数,将输入值作为参数传递并接受输出值作为额外的返回值。
这会声称r1, d1 = Double.TryParse("12.3")应该有效,但事实并非如此。
任何人都可以建议我确切使用out关键字作为参数,以及它如何连接从函数返回多个值,如在此POST中,我与变量与正常变量混淆.任何人都可以帮助我.
我已经找到了这个问题,但我不知道(并没有找到)如何解决它.这里有谁知道如何解决这个问题?我正在使用EMGU,但问题在于c#编码(我对C#来说相当新) - 我认为这与out语句有关,因为我没有太多使用它们:
Image<Gray, Byte> first_image;
if (start_at_frame_1 == true)
{
Perform_custom_routine(imput_frame, out first_image);
}
else
{
Perform_custom_routine(imput_frame, out second_image);
}
Comparison(first_image);
Run Code Online (Sandbox Code Playgroud) 我在这里有一个邮件模板通讯:http: //www.newsletter.vendopor.com/m29-04-13/index2.html
但最后,有一个段落,其中包含该文字:Por favor,envíaestecorreo a las personas que creas le puede ayudar nuestro ...
这段文字,出去的段落(我在CSS中有一个宽度380属性,并继续出去).
它在页面的末尾
我在谷歌搜索过,但找不到解决方案
适用于Chrome,但在Mozilla(最新版本)中,文本即将发布.
非常感谢你的帮助
C#允许将函数参数标记为仅输出:
void func(out int i)
{
i = 44;
}
Run Code Online (Sandbox Code Playgroud)
是否有可能在C/C++中做类似的事情?这可以改善优化.另外应该使警告静音"错误:'myVar'可以在此函数中未初始化使用",当变量未初始化然后传递给函数作为输出参数时.
我使用gcc/g ++(目前是4.4.7)来编译我的代码.
编辑:我知道指针和引用,这不是我要找的.我需要这样的东西:
void func(int* __attribute__((out)) i)
{
*i = 44;
}
void func2()
{
int myVal; // gcc will print warning: 'myVar' may be used uninitialized in this function
func(&myVal);
//...
}
Run Code Online (Sandbox Code Playgroud)
编辑2:需要一些额外的代码来重现警告"'myVar'可能在此函数中未初始化使用".另外,你必须将-Wall -O1传递给gcc.
void __attribute__((const)) func(int* i)
{
*i = 44;
}
int func2()
{
int myVal; // warning here
func(&myVal);
return myVal;
}
Run Code Online (Sandbox Code Playgroud) 根据定义,ref关键字必须在传递之前初始化.而out参数必须在从函数返回之前初始化.
以下是我的片段.
public void TestRef(ref string n)
{
}
public void TestOut(out string n)
{
n = "Hello"; //if I don't initialize, I gets compile time error. & That's right.
}
Run Code Online (Sandbox Code Playgroud)
现在在调用方法时.
string name;
TestOut(out name);//fine
TestRef(ref name) // why not throwing error.
Run Code Online (Sandbox Code Playgroud)
在尝试调用TestRef()时的上述调用中,我没有初始化name参数.但根据我的理解,ref参数必须在传递之前初始化.
它构建和运行没有错误.
为什么在查询子句中不允许输出变量?
如果我在这里使用变量它会失败:
string json = "{'PayDays':['2017-07-07','2017-07-21','2017-08-04','2017-08-18']}";
var pd = JsonConvert.DeserializeObject<Accounting>(json);
var rm = from item in pd.PayDays
where (DateTime.TryParse(item, out DateTime dateresult)) ?
dateresult.Subtract(DateTime.Now).Days >= 0 ? true : false : false
select item;
rm.Dump();
Run Code Online (Sandbox Code Playgroud)
但老方法有效:
DateTime result;
var rm = from item in pd.PayDays
where DateTime.TryParse(item, out result) ? (result.Subtract(DateTime.Now).Days >= 0 ? true : false) : false
select item;
rm.Dump();
Run Code Online (Sandbox Code Playgroud) out ×10
c# ×7
c#-7.0 ×2
python ×2
.net ×1
asp.net ×1
attributes ×1
bounds ×1
c ×1
c++ ×1
gcc ×1
html ×1
keyword ×1
python-3.x ×1
python.net ×1
ref ×1
text ×1
valuetuple ×1
var ×1