I want to get slices from a numpy array and assign them to a larger array.
The slices should be 64 long and should be taken out evenly from the source array.
I tried the following:
r = np.arange(0,magnitude.shape,step)
magnitudes[counter:counter+len(r),ch] = magnitude[r:r+64]
TypeError: only integer arrays with one element can be converted to an index
r is an array is wrong. The variables in the slice must be scalars,
If you want to collect multiple slices you have to do something like
In : x=np.arange(10) In : [x[i:i+3] for i in range(4)] Out: [array([0, 1, 2]), array([1, 2, 3]), array([2, 3, 4]), array([3, 4, 5])] In : np.array([x[i:i+3] for i in range(4)]) Out: 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.