pwtools.num.sliceput¶
- pwtools.num.sliceput(a, b, sl, axis=None)[source]¶
The equivalent of a[<slice or index>]=b, but accepts slices objects instead of array indices or fancy indexing (e.g. a[:,1:]).
- Parameters:
a (numpy ndarray)
sl (slice object, list or tuple of slice objects) –
- axis=<int>
one slice object for that axis
- axis=None
sl is a list or tuple of slice objects, one for each axis. It must index the whole array, i.e. len(sl) == len(a.shape).
axis ({None, int})
- Return type:
The modified a.
Examples
>>> from numpy import s_ >>> a=np.arange(12).reshape((2,6)) >>> a[:,1:3] = 100 >>> a array([[ 0, 100, 100, 3, 4, 5], [ 6, 100, 100, 9, 10, 11]]) >>> sliceput(a, 200, s_[1:3], axis=1) array([[ 0, 200, 200, 3, 4, 5], [ 6, 200, 200, 9, 10, 11]]) >>> sliceput(a, 300, s_[:,1:3]) array([[ 0, 300, 300, 3, 4, 5], [ 6, 300, 300, 9, 10, 11]])