我试图创建一个if语句来检查每个迭代的条件
for in range(100):
B10 = np.random.randint(0, precip.shape[0])
T10 = np.random.randint(0, precip.shape[0] )
if np.abs(B10-T10) <=30:
T10 = np.random.randint(0, precip.shape[0])
我想创建一个if条件,该条件将获得新的T10值,直到每次迭代都满足上面的条件。我该怎么做?你知道吗
Tags:
如果我没弄错的话,这个应该可以:
通过生成所需的随机数来避免循环和if语句。在您的代码中,T10将是一个介于max(0,B10-30)和min(UB,B10+10)之间的随机值,包括两者。你知道吗
其中UB=精确形状[0]. 你知道吗
使用
while
循环而不是for循环:或者您可以使用以下方法避免重新说明变量:
一般来说,当您知道循环的迭代次数或使用集合时,使用
for
循环是一种很好的做法。但是,当您不知道它时,即当它取决于某个条件时,您应该使用while
循环。你知道吗相关问题 更多 >
编程相关推荐