|
31 | 31 | 'arctan2', 'sin', 'cos', 'tan', 'sinh', 'cosh', 'tanh', 'log10', 'sqrt', 'cbrt', 'abs',
|
32 | 32 | 'absolute', 'exp', 'expm1', 'arcsin', 'arccos', 'arctan', 'sign', 'log', 'degrees', 'log2',
|
33 | 33 | 'log1p', 'rint', 'radians', 'reciprocal', 'square', 'negative', 'fix', 'ceil', 'floor',
|
34 |
| - 'trunc', 'logical_not', 'arcsinh', 'arccosh', 'arctanh', 'tensordot', |
35 |
| - 'linspace', 'expand_dims', 'tile', 'arange', 'split', 'concatenate', 'stack', 'vstack', 'mean', |
36 |
| - 'maximum', 'minimum', 'swapaxes', 'clip', 'argmax', 'std', 'var', 'indices', 'copysign', |
37 |
| - 'ravel', 'hanning', 'hamming', 'blackman', 'flip', 'around', 'hypot', 'rad2deg', 'deg2rad'] |
| 34 | + 'trunc', 'logical_not', 'arcsinh', 'arccosh', 'arctanh', 'tensordot', 'linspace', 'expand_dims', |
| 35 | + 'tile', 'arange', 'split', 'hsplit', 'concatenate', 'stack', 'vstack', 'mean', 'maximum', |
| 36 | + 'minimum', 'swapaxes', 'clip', 'argmax', 'std', 'var', 'indices', 'copysign', 'ravel', |
| 37 | + 'hanning', 'hamming', 'blackman', 'flip', 'around', 'hypot', 'rad2deg', 'deg2rad', 'rot90'] |
38 | 38 |
|
39 | 39 |
|
40 | 40 | @set_module('mxnet.ndarray.numpy')
|
@@ -2012,6 +2012,121 @@ def split(ary, indices_or_sections, axis=0):
|
2012 | 2012 | # pylint: enable=redefined-outer-name
|
2013 | 2013 |
|
2014 | 2014 |
|
| 2015 | +# pylint: disable=redefined-outer-name |
| 2016 | +@set_module('mxnet.ndarray.numpy') |
| 2017 | +def hsplit(ary, indices_or_sections): |
| 2018 | + """Split an array into multiple sub-arrays horizontally (column-wise). |
| 2019 | +
|
| 2020 | + This is equivalent to ``split`` with ``axis=0`` if ``ary`` has one |
| 2021 | + dimension, and otherwise that with ``axis=1``. |
| 2022 | +
|
| 2023 | + Parameters |
| 2024 | + ---------- |
| 2025 | + ary : ndarray |
| 2026 | + Array to be divided into sub-arrays. |
| 2027 | + indices_or_sections : int, list of ints or tuple of ints. |
| 2028 | + If `indices_or_sections` is an integer, N, the array will be divided |
| 2029 | + into N equal arrays along `axis`. If such a split is not possible, |
| 2030 | + an error is raised. |
| 2031 | +
|
| 2032 | + If `indices_or_sections` is a list of sorted integers, the entries |
| 2033 | + indicate where along `axis` the array is split. |
| 2034 | +
|
| 2035 | + If an index exceeds the dimension of the array along `axis`, |
| 2036 | + it will raises errors. so index must less than or euqal to |
| 2037 | + the dimension of the array along axis. |
| 2038 | +
|
| 2039 | + Returns |
| 2040 | + ------- |
| 2041 | + sub-arrays : list of ndarrays |
| 2042 | + A list of sub-arrays. |
| 2043 | +
|
| 2044 | + Notes |
| 2045 | + ------ |
| 2046 | + - If `indices_or_sections` is given as an integer, but a split |
| 2047 | + does not result in equal division.It will raises ValueErrors. |
| 2048 | +
|
| 2049 | + - If indices_or_sections is an integer, and the number is 1, it will |
| 2050 | + raises an error. Because single output from split is not supported yet... |
| 2051 | +
|
| 2052 | + See Also |
| 2053 | + -------- |
| 2054 | + split : Split an array into multiple sub-arrays of equal size. |
| 2055 | +
|
| 2056 | + Examples |
| 2057 | + -------- |
| 2058 | + >>> x = np.arange(16.0).reshape(4, 4) |
| 2059 | + >>> x |
| 2060 | + array([[ 0., 1., 2., 3.], |
| 2061 | + [ 4., 5., 6., 7.], |
| 2062 | + [ 8., 9., 10., 11.], |
| 2063 | + [12., 13., 14., 15.]]) |
| 2064 | + >>> np.hsplit(x, 2) |
| 2065 | + [array([[ 0., 1.], |
| 2066 | + [ 4., 5.], |
| 2067 | + [ 8., 9.], |
| 2068 | + [12., 13.]]), |
| 2069 | + array([[ 2., 3.], |
| 2070 | + [ 6., 7.], |
| 2071 | + [10., 11.], |
| 2072 | + [14., 15.]])] |
| 2073 | + >>> np.hsplit(x, [3, 6]) |
| 2074 | + [array([[ 0., 1., 2.], |
| 2075 | + [ 4., 5., 6.], |
| 2076 | + [ 8., 9., 10.], |
| 2077 | + [12., 13., 14.]]), |
| 2078 | + array([[ 3.], |
| 2079 | + [ 7.], |
| 2080 | + [11.], |
| 2081 | + [15.]]), |
| 2082 | + array([], shape=(4, 0), dtype=float32)] |
| 2083 | +
|
| 2084 | + With a higher dimensional array the split is still along the second axis. |
| 2085 | +
|
| 2086 | + >>> x = np.arange(8.0).reshape(2, 2, 2) |
| 2087 | + >>> x |
| 2088 | + array([[[ 0., 1.], |
| 2089 | + [ 2., 3.]], |
| 2090 | + [[ 4., 5.], |
| 2091 | + [ 6., 7.]]]) |
| 2092 | + >>> np.hsplit(x, 2) |
| 2093 | + [array([[[ 0., 1.]], |
| 2094 | + [[ 4., 5.]]]), |
| 2095 | + array([[[ 2., 3.]], |
| 2096 | + [[ 6., 7.]]])] |
| 2097 | +
|
| 2098 | + If ``ary`` has one dimension, 'axis' = 0. |
| 2099 | + >>> x = np.arange(4) |
| 2100 | + array([0., 1., 2., 3.]) |
| 2101 | + >>> np.hsplit(x, 2) |
| 2102 | + [array([0., 1.]), array([2., 3.])] |
| 2103 | +
|
| 2104 | + If you want to produce an empty sub-array, you can see an example. |
| 2105 | + >>> np.hsplit(x, [2, 2]) |
| 2106 | + [array([0., 1.]), array([], dtype=float32), array([2., 3.])] |
| 2107 | + """ |
| 2108 | + indices = [] |
| 2109 | + axis = 1 |
| 2110 | + if (len(ary.shape) == 1): |
| 2111 | + axis = 0 |
| 2112 | + axis_size = ary.shape[axis] |
| 2113 | + if isinstance(indices_or_sections, int): |
| 2114 | + sections = indices_or_sections |
| 2115 | + if axis_size % sections: |
| 2116 | + raise ValueError('array hsplit does not result in an equal division') |
| 2117 | + section_size = int(axis_size / sections) |
| 2118 | + indices = [i * section_size for i in range(sections)] |
| 2119 | + elif isinstance(indices_or_sections, (list, set, tuple)): |
| 2120 | + indices = [0] + list(indices_or_sections) |
| 2121 | + else: |
| 2122 | + raise ValueError('indices_or_sections must either int or tuple of ints') |
| 2123 | + ret = _npi.hsplit(ary, indices, axis, False) |
| 2124 | + if not isinstance(ret, list): |
| 2125 | + raise NotImplementedError('single output from hsplit is not supported yet...') |
| 2126 | + return ret |
| 2127 | +# pylint: enable=redefined-outer-name |
| 2128 | + |
| 2129 | + |
2015 | 2130 | @set_module('mxnet.ndarray.numpy')
|
2016 | 2131 | def concatenate(seq, axis=0, out=None):
|
2017 | 2132 | """Join a sequence of arrays along an existing axis.
|
@@ -3158,3 +3273,49 @@ def hypot(x1, x2, out=None):
|
3158 | 3273 | [ 5., 5., 5.]])
|
3159 | 3274 | """
|
3160 | 3275 | return _ufunc_helper(x1, x2, _npi.hypot, _np.hypot, _npi.hypot_scalar, None, out)
|
| 3276 | + |
| 3277 | + |
| 3278 | +@set_module('mxnet.ndarray.numpy') |
| 3279 | +def rot90(m, k=1, axes=(0, 1)): |
| 3280 | + """ |
| 3281 | + Rotate an array by 90 degrees in the plane specified by axes. |
| 3282 | + Rotation direction is from the first towards the second axis. |
| 3283 | + Parameters |
| 3284 | + ---------- |
| 3285 | + m : ndarray |
| 3286 | + Array of two or more dimensions. |
| 3287 | + k : integer |
| 3288 | + Number of times the array is rotated by 90 degrees. |
| 3289 | + axes: (2,) array_like |
| 3290 | + The array is rotated in the plane defined by the axes. |
| 3291 | + Axes must be different. |
| 3292 | +
|
| 3293 | + Returns |
| 3294 | + ------- |
| 3295 | + y : ndarray |
| 3296 | + A rotated view of `m`. |
| 3297 | +
|
| 3298 | + ----- |
| 3299 | + rot90(m, k=1, axes=(1,0)) is the reverse of rot90(m, k=1, axes=(0,1)) |
| 3300 | + rot90(m, k=1, axes=(1,0)) is equivalent to rot90(m, k=-1, axes=(0,1)) |
| 3301 | + Examples |
| 3302 | + -------- |
| 3303 | + >>> m = np.array([[1,2],[3,4]], 'int') |
| 3304 | + >>> m |
| 3305 | + array([[1, 2], |
| 3306 | + [3, 4]], dtype=int64) |
| 3307 | + >>> np.rot90(m) |
| 3308 | + array([[2, 4], |
| 3309 | + [1, 3]], dtype=int64) |
| 3310 | + >>> np.rot90(m, 2) |
| 3311 | + array([[4, 3], |
| 3312 | + [2, 1]], dtype=int64) |
| 3313 | + >>> m = np.arange(8).reshape((2,2,2)) |
| 3314 | + >>> np.rot90(m, 1, (1,2)) |
| 3315 | + array([[[1., 3.], |
| 3316 | + [0., 2.]], |
| 3317 | +
|
| 3318 | + [[5., 7.], |
| 3319 | + [4., 6.]]]) |
| 3320 | + """ |
| 3321 | + return _npi.rot90(m, k=k, axes=axes) |
0 commit comments