Perhaps this has been raised and addressed somewhere else but I haven't found it. Suppose we have a numpy array:
a = np.arange(100).reshape(10,10)
b = np.zeros(a.shape)
start = np.array([1,4,7]) # can be arbitrary but valid values
end = np.array([3,6,9]) # can be arbitrary but valid values
start
and end
both have valid values so that each slicing is also valid for a
.
I wanted to copy value of subarrays in a
to corresponding spots in in b
:
b[:, start:end] = a[:, start:end] #error
this syntax doesn't work, but it's equivalent to:
b[:, start[0]:end[0]] = a[:, start[0]:end[0]]
b[:, start[1]:end[1]] = a[:, start[1]:end[1]]
b[:, start[2]:end[2]] = a[:, start[2]:end[2]]
I wonder if there is a better way of doing this instead of an explicit for-loop over the start
and end
arrays.
Thanks!