<?xml version="1.0" encoding="utf-8" ?>
<testcase>
<date>4/12/13</date>
<name>Mrinal</name>
<subject>xmlTest</subject>
</testcase>
Run Code Online (Sandbox Code Playgroud)
我试图使用c#读取上面的xml,但是我在try catch块中得到null异常可以任何正文建议所需的更改.
static void Main(string[] args)
{
XmlDocument xd = new XmlDocument();
xd.Load("C:/Users/mkumar/Documents/testcase.xml");
XmlNodeList nodelist = xd.SelectNodes("/testcase"); // get all <testcase> nodes
foreach (XmlNode node in nodelist) // for each <testcase> node
{
CommonLib.TestCase tc = new CommonLib.TestCase();
try
{
tc.name = node.Attributes.GetNamedItem("date").Value;
tc.date = node.Attributes.GetNamedItem("name").Value;
tc.sub = node.Attributes.GetNamedItem("subject").Value;
}
catch (Exception e)
{
MessageBox.Show("Error in reading XML", "xmlError", MessageBoxButtons.OK);
}
Run Code Online (Sandbox Code Playgroud)
........ .....
嗨,我有以下问题,我想实现:
给定整数数组:1 2 7 5 1 2
我想找到最大相邻乘积之和,即1+2+(5*7)+1+2 = 41
给定整数数组:1 2 4 2 4 2我想找到最大相邻乘积之和 1+(2*4)+(2*4)+2 = 19
乘法的约束是只能将一个相邻元素用于乘法。也就是说,如果我们有2 4 2数组,我们将其计算为2+(4*2) or (2*4)+2。
我是动态编程的初学者。我无法弄清楚以下问题的重复关系。
有人可以建议点什么吗?
我正在尝试使用scipy的optimizer.minimize函数,但我无法弄清楚将args传递给目标函数的确切方法.我有以下代码,根据我应该工作正常但是给我错误的参数数量.
result = minimize(compute_cost, x0, args=(parameter), method='COBYLA',constraints=cons, options={'maxiter':10000,'rhobeg':20})
Run Code Online (Sandbox Code Playgroud)
这是目标函数的函数签名: def compute_cost(x,parameter)
parameter 是一个有51键值对的字典.
这会出现以下错误:
capi_return is NULL
Call-back cb_calcfc_in__cobyla__user__routines failed.
Traceback (most recent call last):
File "C:\..\resource_optimizer.py", line 138, in <module>
result = minimize(compute_cost, x0, args=(parameter), method='COBYLA',constraints=cons, options={'maxiter':10000,'rhobeg':20})
File "C:\Python27\lib\site-packages\scipy\optimize\_minimize.py", line 432, in minimize
return _minimize_cobyla(fun, x0, args, constraints, **options)
File "C:\Python27\lib\site-packages\scipy\optimize\cobyla.py", line 246, in _minimize_cobyla
dinfo=info)
File "C:\Python27\lib\site-packages\scipy\optimize\cobyla.py", line 238, in calcfc
f = fun(x, *args)
TypeError: compute_cost() takes exactly 2 arguments (52 given)
有人可以帮我解决这个问题.