如果条件作为Python For循环中的停止条件

时间:2020-09-04 21:32:19

标签: python python-3.x for-loop

我希望编写一个for循环,以使停止标准满足列表中两个连续元素之间的差异。该列表是从for循环中追加的,如以下代码所示:

m, n = 100, 4
counter1 = []
tol = 1e-8

x_not = np.zeros(n)
for iterate in range(100):
    for rows in range(m):
        y = My_func(x_not, rows)
        x_not = y
        counter1.append(norm(x_not))
        if counter1[i-1] - counter1[i] < tol:
            break

我希望for循环在任何两个连续元素小于tol时停止。我需要有人来帮助在Python中实现此代码。 My_func是预定义的功能。

0 个答案:

没有答案
相关问题