[Numpy-discussion] New (old) function proposal.
Sebastian Berg
sebastian at sipsolutions.net
Tue Feb 18 11:27:26 EST 2014
On Di, 2014-02-18 at 09:05 -0700, Charles R Harris wrote:
> Hi All,
>
>
> There is an old ticket, #1499, that suggest adding a segment_axis
> function.
>
> def segment_axis(a, length, overlap=0, axis=None, end='cut', endvalue=0):
> """Generate a new array that chops the given array along the given axis
> into overlapping frames.
>
> Parameters
> ----------
> a : array-like
> The array to segment
> length : int
> The length of each frame
> overlap : int, optional
> The number of array elements by which the frames should overlap
> axis : int, optional
> The axis to operate on; if None, act on the flattened array
> end : {'cut', 'wrap', 'end'}, optional
> What to do with the last frame, if the array is not evenly
> divisible into pieces.
>
> - 'cut' Simply discard the extra values
> - 'wrap' Copy values from the beginning of the array
> - 'pad' Pad with a constant value
>
> endvalue : object
> The value to use for end='pad'
>
>
> Examples
> --------
> >>> segment_axis(arange(10), 4, 2)
> array([[0, 1, 2, 3],
> [2, 3, 4, 5],
> [4, 5, 6, 7],
> [6, 7, 8, 9]])
>
>
> Is there and interest in having this function available?
>
Just to note, there have been similar proposals with a rolling_window
function. It could be made ND aware, too (though maybe this one is
also).
>
> Chuck
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list