pymks/stats.py
def _truncate(a, shape):
    """
    _truncates the edges of the array, a, based on the shape. This is
    used to unpad a padded convolution.

    Args:
        a: array to be truncated
        shape: new shape of array

    Returns:
        truncated array

    Example

    >>> print _truncate(np.arange(10).reshape(1, 10, 1), (1, 5))[0, ..., 0]
    [3 4 5 6 7]
    >>> print _truncate(np.arange(9).reshape(1, 9, 1), (1, 5))[0, ..., 0]
    [2 3 4 5 6]
    >>> print _truncate(np.arange(10).reshape((1, 10, 1)), (1, 4))[0, ..., 0]
    [3 4 5 6]
    >>> print _truncate(np.arange(9).reshape((1, 9, 1)), (1, 4))[0, ..., 0]
    [2 3 4 5]

    >>> a = np.arange(5 * 4).reshape((1, 5, 4, 1))
    >>> print _truncate(a, shape=(1, 3, 2))[0, ..., 0]
    [[ 5  6]
     [ 9 10]
     [13 14]]

    >>> a = np.arange(5 * 4 * 3).reshape((1, 5, 4, 3, 1))
    >>> assert (_truncate(a, (1, 2, 2, 1))[0, ..., 0]  ==
    ...         [[[16], [19]], [[28], [31]]]).all()

    """
    a_shape = np.array(a.shape)
    n = len(shape)
    new_shape = a_shape.copy()
    new_shape[:n] = shape
    diff_shape = a_shape - new_shape
    index0 = (diff_shape + (diff_shape % 2) * (new_shape % 2)) / 2
    index1 = index0 + new_shape
    multi_slice = tuple(slice(index0[ii], index1[ii]) for ii in range(n))
    return a[multi_slice]

    _truncates the edges of the array, a, based on the shape. This is
    used to unpad a padded convolution.

    Args:
        a: array to be truncated
        shape: new shape of array

    Returns:
        truncated array

    Example

    >>> print _truncate(np.arange(10).reshape(1, 10, 1), (1, 5))[0, ..., 0]
    [3 4 5 6 7]
    >>> print _truncate(np.arange(9).reshape(1, 9, 1), (1, 5))[0, ..., 0]
    [2 3 4 5 6]
    >>> print _truncate(np.arange(10).reshape((1, 10, 1)), (1, 4))[0, ..., 0]
    [3 4 5 6]
    >>> print _truncate(np.arange(9).reshape((1, 9, 1)), (1, 4))[0, ..., 0]
    [2 3 4 5]

    >>> a = np.arange(5 * 4).reshape((1, 5, 4, 1))
    >>> print _truncate(a, shape=(1, 3, 2))[0, ..., 0]
    [[ 5  6]
     [ 9 10]
     [13 14]]

    >>> a = np.arange(5 * 4 * 3).reshape((1, 5, 4, 3, 1))
    >>> assert (_truncate(a, (1, 2, 2, 1))[0, ..., 0]  ==
    ...         [[[16], [19]], [[28], [31]]]).all()

    
_truncates the edges of the array, a, based on the shape. This is
used to unpad a padded convolution.
_truncates the edges of the array a based on the shape . This is used to unpad a padded convolution .
def _truncate(a, shape):
    a_shape = np.array(a.shape)
    n = len(shape)
    new_shape = a_shape.copy()
    new_shape[:n] = shape
    diff_shape = a_shape - new_shape
    index0 = (diff_shape + (diff_shape % 2) * (new_shape % 2)) / 2
    index1 = index0 + new_shape
    multi_slice = tuple(slice(index0[ii], index1[ii]) for ii in range(n))
    return a[multi_slice]
def _truncate ( a , shape ) : a_shape = np . array ( a . shape ) n = len ( shape ) new_shape = a_shape . copy ( ) new_shape [ : n ] = shape diff_shape = a_shape - new_shape index0 = ( diff_shape + ( diff_shape % 2 ) * ( new_shape % 2 ) ) / 2 index1 = index0 + new_shape multi_slice = tuple ( slice ( index0 [ ii ] , index1 [ ii ] ) for ii in range ( n ) ) return a [ multi_slice ]
_truncates the edges of the array, a, based on the shape.
_truncates the edges of the array a based on the shape .
"""
    _truncates the edges of the array, a, based on the shape. This is
    used to unpad a padded convolution.

    Args:
        a: array to be truncated
        shape: new shape of array

    Returns:
        truncated array

    Example

    >>> print _truncate(np.arange(10).reshape(1, 10, 1), (1, 5))[0, ..., 0]
    [3 4 5 6 7]
    >>> print _truncate(np.arange(9).reshape(1, 9, 1), (1, 5))[0, ..., 0]
    [2 3 4 5 6]
    >>> print _truncate(np.arange(10).reshape((1, 10, 1)), (1, 4))[0, ..., 0]
    [3 4 5 6]
    >>> print _truncate(np.arange(9).reshape((1, 9, 1)), (1, 4))[0, ..., 0]
    [2 3 4 5]

    >>> a = np.arange(5 * 4).reshape((1, 5, 4, 1))
    >>> print _truncate(a, shape=(1, 3, 2))[0, ..., 0]
    [[ 5  6]
     [ 9 10]
     [13 14]]

    >>> a = np.arange(5 * 4 * 3).reshape((1, 5, 4, 3, 1))
    >>> assert (_truncate(a, (1, 2, 2, 1))[0, ..., 0]  ==
    ...         [[[16], [19]], [[28], [31]]]).all()

    """
None
a
array to be truncated
array to be truncated
shape
new shape of array
new shape of array