@@ -2003,18 +2003,46 @@ def _array_perimeter(arr):
2003
2003
2004
2004
2005
2005
def _unfold (arr , axis , size , step ):
2006
- """Append an extra dimension containing sliding windows along **axis**.
2006
+ """
2007
+ Append an extra dimension containing sliding windows along *axis*.
2007
2008
2008
- All windows are of size ** size** and begin with every ** step* * elements.
2009
+ All windows are of size *size* and begin with every *step* elements.
2009
2010
2010
2011
Parameters
2011
2012
----------
2012
2013
arr : ndarray, shape (N_1, ..., N_k)
2013
2014
The input array
2015
+ axis : int
2016
+ Axis along which the windows are extracted
2017
+ size : int
2018
+ Size of the windows
2019
+ step : int
2020
+ Stride between first elements of subsequent windows.
2014
2021
2015
2022
Returns
2016
2023
-------
2017
2024
windows : ndarray, shape (N_1, ..., 1 + (N_axis-size)/step, ..., N_k, size)
2025
+
2026
+ Examples
2027
+ --------
2028
+ >>> i, j = np.ogrid[:3,:7]
2029
+ >>> a = i*10 + j
2030
+ >>> a
2031
+ array([[ 0, 1, 2, 3, 4, 5, 6],
2032
+ [10, 11, 12, 13, 14, 15, 16],
2033
+ [20, 21, 22, 23, 24, 25, 26]])
2034
+ >>> _unfold(a, axis=1, size=3, step=2)
2035
+ array([[[ 0, 1, 2],
2036
+ [ 2, 3, 4],
2037
+ [ 4, 5, 6]],
2038
+
2039
+ [[10, 11, 12],
2040
+ [12, 13, 14],
2041
+ [14, 15, 16]],
2042
+
2043
+ [[20, 21, 22],
2044
+ [22, 23, 24],
2045
+ [24, 25, 26]]])
2018
2046
"""
2019
2047
new_shape = [* arr .shape , size ]
2020
2048
new_strides = [* arr .strides , arr .strides [axis ]]
@@ -2027,19 +2055,25 @@ def _unfold(arr, axis, size, step):
2027
2055
2028
2056
2029
2057
def _array_patch_perimeters (x , rstride , cstride ):
2030
- """Extract perimeters of patches from **arr**.
2058
+ """
2059
+ Extract perimeters of patches from *arr*.
2031
2060
2032
- Extracted patches are of size (** rstride** + 1) x (** cstride* * + 1) and
2061
+ Extracted patches are of size (*rstride* + 1) x (*cstride* + 1) and
2033
2062
share perimeters with their neighbors. The ordering of the vertices matches
2034
2063
that returned by ``_array_perimeter``.
2035
2064
2036
2065
Parameters
2037
2066
----------
2038
- arr : ndarray, shape (N, M)
2067
+ x : ndarray, shape (N, M)
2068
+ Input array
2069
+ rstride : int
2070
+ Vertical (row) stride between corresponding elements of each patch
2071
+ cstride : int
2072
+ Horizontal (column) stride between corresponding elements of each patch
2039
2073
2040
2074
Returns
2041
2075
-------
2042
- patches : ndarray, shape (N / rstride * M / cstride, 2(rstride + cstride))
2076
+ patches : ndarray, shape (N/ rstride * M/ cstride, 2 * (rstride + cstride))
2043
2077
"""
2044
2078
assert rstride > 0 and cstride > 0
2045
2079
assert (x .shape [0 ] - 1 ) % rstride == 0
0 commit comments