元素循环范围的数值变化值
为简单起见,我有一系列元素:阵列([0,1,2,3,4,5,6,7,7,8,9,10,11,11,12,13,14,14,15,16,17,18,19])
。
从0,每个nth元素开始,我想更改下一个M元素的值。
例如:n = 5; m = 2
,我想将元素设置为100。
输出应该是:阵列([100,100,2,3,4,100,100,100,7,8,9,100,100,100,100,12,13,14,100,100,100,17,18,19])
这是在一行(带指数)中进行的努力方法吗?还是仅通过循环或列表理解 - 哪个会慢。
I have an array of elements, for simplicity:array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])
.
Starting with 0, every nth element, I'd like to change the value of the next m elements.
For example: n=5; m=2
and I'd like to set the elements to 100.
The output should be something like:array([ 100, 100, 2, 3, 4, 100, 100, 7, 8, 9, 100, 100, 12, 13, 14, 100, 100, 17, 18, 19])
is this a numpy way to do it in one line (with indices)? or only by looping or list comprehension - which will be slower..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下可以完成这项工作
The following could do the job