所以我有一个设置了一些选项的迭代器,我想在一个简单的while或for循环中嵌套它,但似乎不允许这样做,这是我的代码。谢谢您的提前帮助。
struct Distance
{
public void SetFeet(int feet) { Value = feet; }
public void SetMiles(float miles) { Value = (int)(miles * 5280f); }
public int GetFeet() { return Value; }
public float GetMiles() { return Value / 5280f; }
private int Value;
}
class Distances
{
public Distance Dist1;//here
public Distance Dist2;//and here
}
class Program
{
static void Main(string[] args)
{
Distances distances = new Distances();
distances.Dist1.SetFeet(1000);
distances.Dist2.SetFeet(2000);
Console.WriteLine("Dist1: {0}, Dist2: {1}", distances.Dist1.GetMiles(),
distances.Dist2.GetMiles());
Console.ReadLine();
}
}
答案 0 :(得分:2)
按现状,num_iters
在while
循环中没有改变。
您可以使用for
循环:
for _ in range(num_iters):
with np.nditer(X, order='C', flags=['external_loop'], op_flags=['readwrite']) as it:
for x in it:
theta[0] = theta[0] - (alpha * (x[0] * theta[0] + x[1] * theta[1] - x[2]))/m
theta[1] = theta[1] - ((alpha * (x[0] * theta[0] + x[1] * theta[1] - x[2]))*x[1])/m
您可以改用while
循环,但需要自己增加计数器。