我是scipy的新手,以下代码似乎不起作用:
from scipy import optimize
def f(x, y):
return x * x - 3 + y
def main():
x0 = 0.1
y = 1
res = optimize.newton(f(x0,y), x0)
print (res)
Run Code Online (Sandbox Code Playgroud)
我收到的错误是:
File "C:\Python27\lib\site-packages\scipy\optimize\zeros.py", line 144, in newton
q0 = func(*((p0,) + args))
TypeError: 'float' object is not callable
Run Code Online (Sandbox Code Playgroud) 我本来希望这段代码能够用speeed执行,但是对于5000个元素的列表,它在我杀死它之前运行了超过20分钟.
是因为list.contains()吗?
有任何想法吗?
public static int PNum(int N)
{
List<int> result = new List<int>();
for (int i = 1; i <= N; i++)
result.Add(i * (3 * i - 1) / 2);
int len = result.Count;
int minDiff = 10000;
int sum = 0, diff = 0;
for (int i = 0; i <= len - 1; i++)
{
for (int j = i + 1; j <= len - 1; j++)
{
diff = result[j] - result[i];
if (result.Contains(diff)) …Run Code Online (Sandbox Code Playgroud) 在 Python 中,我使用此声明创建了一个最多包含 1000 万个元素的列表,
res = [0, 1] * (N // 2) + [1]
Run Code Online (Sandbox Code Playgroud)
有没有办法在不迭代列表的情况下在 C# 中执行等效操作?我正在尝试这样的事情,
List<int> res = Enumerable.Repeat(0, N).ToList();
Run Code Online (Sandbox Code Playgroud)
但不能完全弄清楚正确的语法。