Re: [Numpy-discussion] New (old) function proposal.

2014-02-19 Thread Warren Weckesser
On Tue, Feb 18, 2014 at 11:27 AM, Sebastian Berg sebast...@sipsolutions.net
 wrote:

 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).



For example:  https://github.com/numpy/numpy/pull/31

Warren



 
  Chuck
 
  ___
  NumPy-Discussion mailing list
  NumPy-Discussion@scipy.org
  http://mail.scipy.org/mailman/listinfo/numpy-discussion


 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] New (old) function proposal.

2014-02-18 Thread Benjamin Root
yes, but I don't like the name too much. Unfortunately, I can't think of a
better one.

Ben Root


On Tue, Feb 18, 2014 at 11:05 AM, Charles R Harris 
charlesr.har...@gmail.com wrote:

 Hi All,

 There is an old ticket, #1499 https://github.com/numpy/numpy/issues/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?

 Chuck

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] New (old) function proposal.

2014-02-18 Thread Sebastian Berg
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@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] New (old) function proposal.

2014-02-18 Thread Nathaniel Smith
On 18 Feb 2014 11:05, Charles R Harris charlesr.har...@gmail.com 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?

I'd use it, though haven't looked at the details of this api per set yet.

rolling_window or shingle are better names.

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.

-n
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] New (old) function proposal.

2014-02-18 Thread Charles R Harris
On Tue, Feb 18, 2014 at 9:40 AM, Nathaniel Smith n...@pobox.com wrote:

 On 18 Feb 2014 11:05, Charles R Harris charlesr.har...@gmail.com
 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?

 I'd use it, though haven't looked at the details of this api per set yet.

 rolling_window or shingle are better names.

 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.


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.

Where does 'shingle' come from. I can see the analogy but haven't seen that
as a technical term.

Chuck
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] New (old) function proposal.

2014-02-18 Thread Jaime Fernández del Río
On Tue, Feb 18, 2014 at 9:03 AM, Charles R Harris charlesr.har...@gmail.com
 wrote:




 On Tue, Feb 18, 2014 at 9:40 AM, Nathaniel Smith n...@pobox.com wrote:

 On 18 Feb 2014 11:05, Charles R Harris charlesr.har...@gmail.com
 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?

 I'd use it, though haven't looked at the details of this api per set yet.

 rolling_window or shingle are better names.

 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.


 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.

 Where does 'shingle' come from. I can see the analogy but haven't seen
 that as a technical term.


In an inkjet printing pipeline, one of the last steps is to split the image
into the several passes that will be needed to physically print it. This is
often done with a tiled, non-overlapping mask, known as a shingling mask.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] New (old) function proposal.

2014-02-18 Thread Nathaniel Smith
On 18 Feb 2014 12:04, Charles R Harris charlesr.har...@gmail.com wrote:
 Where does 'shingle' come from. I can see the analogy but haven't seen
that as a technical term.

It just seems like a good name :-).

-n
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] New (old) function proposal.

2014-02-18 Thread Tony Yu
On Tue, Feb 18, 2014 at 11:11 AM, Jaime Fernández del Río 
jaime.f...@gmail.com wrote:




 On Tue, Feb 18, 2014 at 9:03 AM, Charles R Harris 
 charlesr.har...@gmail.com wrote:




 On Tue, Feb 18, 2014 at 9:40 AM, Nathaniel Smith n...@pobox.com wrote:

 On 18 Feb 2014 11:05, Charles R Harris charlesr.har...@gmail.com
 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?

 I'd use it, though haven't looked at the details of this api per set yet.

 rolling_window or shingle are better names.

 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.


 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.

 Where does 'shingle' come from. I can see the analogy but haven't seen
 that as a technical term.


 In an inkjet printing pipeline, one of the last steps is to split the
 image into the several passes that will be needed to physically print it.
 This is often done with a tiled, non-overlapping mask, known as a
 shingling mask.


Just for reference, scikit-image has a similar function (w/o padding)
called `view_as_blocks`:

http://scikit-image.org/docs/0.9.x/api/skimage.util.html#view-as-blocks

(and a rolling-window version called `view_as_windows`).

Cheers,
-Tony
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion