[英]How can I partially fill a numpy array with a value given a range?
Given a numpy array, a range, and a value, how can I fill the array with the value inside the range? 给定一个numpy数组,一个范围和一个值,如何用范围内的值填充数组?
Is there a way that is faster than filling it in manually with a loop one by one? 有没有比手动逐个循环填充更快的方法?
Edit: 编辑:
myArray = np.zeros(10)
What I want: [0, 0, 0, 0, 1, 1, 1, 0, 0, 0] 我想要的是:[0,0,0,0,1,1,1,0,0,0]
arr = np.zeros(10)
arr[4:7] = 1
print(arr)
Output: 输出:
array([0., 0., 0., 0., 1., 1., 1., 0., 0., 0.])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.