magnitude[r:r+64] where r is an array is wrong. The variables in the slice must be scalars, magnitude[3:67], not magnitude[[1,2,3]:[5,6,7]].
If you want to collect multiple slices you have to do something like
In [345]: x=np.arange(10)
In [346]: [x[i:i+3] for i in range(4)]
Out[346]: [array([0, 1, 2]), array([1, 2, 3]), array([2, 3, 4]), array([3, 4, 5])]
In [347]: np.array([x[i:i+3] for i in range(4)])
Out[347]:
array([[0, 1, 2],
[1, 2, 3],
[2, 3, 4],
[3, 4, 5]])
Other SO questions have explored variations on this, trying to find the fastest, but it's hard to get around some sort loop or list comprehension.
I'd suggest working with this answer, and come back with a new question, and a small working example, if you think you need more speed.
Answer from hpaulj on Stack Overflowpython - Assign value to multiple slices in numpy - Stack Overflow
python - Numpy assigning to slice, when is the array copied - Stack Overflow
python - Numpy: Trying to set value on a slice of a slice of an array - Stack Overflow
Idea: Allow assigning a scalar to all elements of a list slice, just as is allowed with a numpy array - Ideas - Discussions on Python.org
You might also consider using np.r_:
http://docs.scipy.org/doc/numpy/reference/generated/numpy.r_.html
ii = np.r_[0:3,7:10]
a[ii] = 10
In [11]: a
Out[11]: array([ 10, 10, 10, 3, 4, 5, 6, 10, 10, 10])
a = np.arange(10)
a[[range(3)+range(6,9)]] = 10
#or a[[0,1,2,6,7,8]] = 10
print a
that should work I think ... I dont know that its quite what you want though
You need to slice ind_a first:
r[np.array(ind_a)[ind_b]] = 1
print(r)
array([1., 0., 0., 0., 0., 0., 0., 0., 1., 1., 0., 0., 0., 0., 0.])
I am slightly confused by the wording of your question, but let me see if this helps.
Question: Take numbers from ind_b as indexes for ind_a. Use the selected numbers from ind_a as the indexes of r that should be set to 1.
Answer: Use a for loop, as follows:
for i in ind_b:
j = ind_a[i]
r[j] = 1
This will change r as follows:
>>> r
[1, 1, 2, 3, 4, 5, 6, 7, 1, 1, 10, 11, 12, 13, 14]