我有以下示例代码:
T(n) = sum_{p = 1}{n^2} sum_{q=1}{p} (1) = sum_{p=1}{n^2} (p) = 1 + 2 + 3 + ... + n^2 = n^2(n^2 + 1)/2 = Theta(n^4)
哪个给我输出:
l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def batch_gen(data, batch_size):
for i in range(0, len(data), batch_size):
yield data[i:i+batch_size]
batch_size = randint(1,4)
n = 0
print("batch_size is {}".format(batch_size))
for i in batch_gen(l, batch_size):
for x in i:
print(x)
print("loop {}".format(n))
n += 1
batch_size = randint(1,4)
这是我要查找的输出,但是总是在for循环之外,从batch_size = randint(1,4)设置batch_size。
我正在为循环的每次迭代寻找一个随机的batch_size,并且每个下一个循环都在最后一个循环停止直到随机长度列表完成的地方拾取。
任何帮助将不胜感激!