<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 18, 2014 at 9:40 AM, Nathaniel Smith <span dir="ltr"><<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><p dir="ltr">On 18 Feb 2014 11:05, "Charles R Harris" <<a href="mailto:charlesr.harris@gmail.com" target="_blank">charlesr.harris@gmail.com</a>> wrote:<br>

><br>
> Hi All,<br>
><br>
> There is an old ticket, #1499, that suggest adding a segment_axis function.<br>
><br>
> def segment_axis(a, length, overlap=0, axis=None, end='cut', endvalue=0):<br>
>     """Generate a new array that chops the given array along the given axis<br>
>     into overlapping frames.<br>
><br>
>     Parameters<br>
>     ----------<br>
>     a : array-like<br>
>         The array to segment<br>
>     length : int<br>
>         The length of each frame<br>
>     overlap : int, optional<br>
>         The number of array elements by which the frames should overlap<br>
>     axis : int, optional<br>
>         The axis to operate on; if None, act on the flattened array<br>
>     end : {'cut', 'wrap', 'end'}, optional<br>
>         What to do with the last frame, if the array is not evenly<br>
>         divisible into pieces. <br>
><br>
>             - 'cut'   Simply discard the extra values<br>
>             - 'wrap'  Copy values from the beginning of the array<br>
>             - 'pad'   Pad with a constant value<br>
><br>
>     endvalue : object<br>
>         The value to use for end='pad'<br>
><br>
><br>
>     Examples<br>
>     --------<br>
>     >>> segment_axis(arange(10), 4, 2)<br>
>     array([[0, 1, 2, 3],<br>
>            [2, 3, 4, 5],<br>
>            [4, 5, 6, 7],<br>
>            [6, 7, 8, 9]])<br>
><br>
><br>
> Is there and interest in having this function available?</p>
</div></div><p dir="ltr">I'd use it, though haven't looked at the details of this api per set yet.</p>
<p dir="ltr">rolling_window or shingle are better names.</p>
<p dir="ltr">It should probably be documented and implemented to return a view when possible (using stride tricks). Along with a note that whether this is possible depends heavily on 32- vs. 64-bitness.</p></blockquote><div>
<br></div><div>I believe it does return views when possible. There are two patches attached to the issue, one for the function and another for tests. So here is an easy commit for someone ;) The original author seems to be Anne Archibald, who should be mentioned if this is put in.<br>
<br></div><div>Where does 'shingle' come from. I can see the analogy but haven't seen that as a technical term.<br><br></div><div>Chuck<br></div></div></div></div>