简体   繁体   English

每 x 步添加 n 重复 N 次

[英]add n every x step repeat N times

after hours spent searching for a solution on SO I am here to ask for help.在花了几个小时在 SO 上寻找解决方案后,我在这里寻求帮助。

I want to generate onsets where at each step I can add n at every x step and I want to repeat it N times, eg: A1 = 0 , A2 = A1+n , and repeat this until AN = AN-1 + n .我想生成开始,在每个步骤中我可以在每个x步骤添加n并且我想重复它N次,例如: A1 = 0A2 = A1+n ,并重复这个直到AN = AN-1 + n

I tried with numpy.arrange but it gives only a start and a stop there is no option to specify a repetition.我试过numpy.arrange但它只给出一个开始和一个停止,没有指定重复的选项。

Thanks for your help.谢谢你的帮助。

I made a quick code.我做了一个快速的代码。
N is the amount the code will count up to from 1. N 是代码将从 1 开始计数的数量。
x is the number of times you want to read the code before actually printing the line. x 是在实际打印行之前要阅读代码的次数。
n is the number it increases by. n 是它增加的数字。 (the loop's speed) (循环速度)

N = 10
n = 1
i = 1
x = 4
# Once i becomes 11 it leaves the loop.
while(i <= N):
    # prints the statement every x times.
    if (i % x) == 0:
        print("This runs every " + str(x) + " times.")
        print("Now printing: " + str(i))
    i += n

Output:输出:

This runs every 4 times.这每 4 次运行一次。
Now printing: 0正在打印:0
This runs every 4 times.这每 4 次运行一次。
Now printing: 4正在印刷:4
This runs every 4 times.这每 4 次运行一次。
Now printing: 8正在印刷:8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM