|
32 | 32 | 'absolute', 'exp', 'expm1', 'arcsin', 'arccos', 'arctan', 'sign', 'log', 'degrees', 'log2', |
33 | 33 | 'log1p', 'rint', 'radians', 'reciprocal', 'square', 'negative', 'fix', 'ceil', 'floor', |
34 | 34 | 'trunc', 'logical_not', 'arcsinh', 'arccosh', 'arctanh', 'tensordot', |
35 | | - 'linspace', 'expand_dims', 'tile', 'arange', 'split', 'concatenate', 'stack', 'vstack', 'mean', |
| 35 | + 'linspace', 'expand_dims', 'tile', 'arange', 'split', 'hsplit', 'concatenate', 'stack', 'vstack', 'mean', |
36 | 36 | 'maximum', 'minimum', 'swapaxes', 'clip', 'argmax', 'std', 'var', 'indices', 'copysign', |
37 | 37 | 'ravel', 'hanning', 'hamming', 'blackman', 'flip', 'around', 'hypot', 'rad2deg', 'deg2rad', |
38 | | - 'unique', 'lcm', 'tril', 'identity', 'take'] |
| 38 | + 'unique', 'lcm', 'tril', 'identity', 'take', 'rot90'] |
39 | 39 |
|
40 | 40 |
|
41 | 41 | @set_module('mxnet.ndarray.numpy') |
@@ -2318,6 +2318,121 @@ def split(ary, indices_or_sections, axis=0): |
2318 | 2318 | # pylint: enable=redefined-outer-name |
2319 | 2319 |
|
2320 | 2320 |
|
| 2321 | +# pylint: disable=redefined-outer-name |
| 2322 | +@set_module('mxnet.ndarray.numpy') |
| 2323 | +def hsplit(ary, indices_or_sections): |
| 2324 | + """Split an array into multiple sub-arrays horizontally (column-wise). |
| 2325 | +
|
| 2326 | + This is equivalent to ``split`` with ``axis=0`` if ``ary`` has one |
| 2327 | + dimension, and otherwise that with ``axis=1``. |
| 2328 | +
|
| 2329 | + Parameters |
| 2330 | + ---------- |
| 2331 | + ary : ndarray |
| 2332 | + Array to be divided into sub-arrays. |
| 2333 | + indices_or_sections : int, list of ints or tuple of ints. |
| 2334 | + If `indices_or_sections` is an integer, N, the array will be divided |
| 2335 | + into N equal arrays along `axis`. If such a split is not possible, |
| 2336 | + an error is raised. |
| 2337 | +
|
| 2338 | + If `indices_or_sections` is a list of sorted integers, the entries |
| 2339 | + indicate where along `axis` the array is split. |
| 2340 | +
|
| 2341 | + If an index exceeds the dimension of the array along `axis`, |
| 2342 | + it will raises errors. so index must less than or euqal to |
| 2343 | + the dimension of the array along axis. |
| 2344 | +
|
| 2345 | + Returns |
| 2346 | + ------- |
| 2347 | + sub-arrays : list of ndarrays |
| 2348 | + A list of sub-arrays. |
| 2349 | +
|
| 2350 | + Notes |
| 2351 | + ------ |
| 2352 | + - If `indices_or_sections` is given as an integer, but a split |
| 2353 | + does not result in equal division.It will raises ValueErrors. |
| 2354 | +
|
| 2355 | + - If indices_or_sections is an integer, and the number is 1, it will |
| 2356 | + raises an error. Because single output from split is not supported yet... |
| 2357 | +
|
| 2358 | + See Also |
| 2359 | + -------- |
| 2360 | + split : Split an array into multiple sub-arrays of equal size. |
| 2361 | +
|
| 2362 | + Examples |
| 2363 | + -------- |
| 2364 | + >>> x = np.arange(16.0).reshape(4, 4) |
| 2365 | + >>> x |
| 2366 | + array([[ 0., 1., 2., 3.], |
| 2367 | + [ 4., 5., 6., 7.], |
| 2368 | + [ 8., 9., 10., 11.], |
| 2369 | + [12., 13., 14., 15.]]) |
| 2370 | + >>> np.hsplit(x, 2) |
| 2371 | + [array([[ 0., 1.], |
| 2372 | + [ 4., 5.], |
| 2373 | + [ 8., 9.], |
| 2374 | + [12., 13.]]), |
| 2375 | + array([[ 2., 3.], |
| 2376 | + [ 6., 7.], |
| 2377 | + [10., 11.], |
| 2378 | + [14., 15.]])] |
| 2379 | + >>> np.hsplit(x, [3, 6]) |
| 2380 | + [array([[ 0., 1., 2.], |
| 2381 | + [ 4., 5., 6.], |
| 2382 | + [ 8., 9., 10.], |
| 2383 | + [12., 13., 14.]]), |
| 2384 | + array([[ 3.], |
| 2385 | + [ 7.], |
| 2386 | + [11.], |
| 2387 | + [15.]]), |
| 2388 | + array([], shape=(4, 0), dtype=float32)] |
| 2389 | +
|
| 2390 | + With a higher dimensional array the split is still along the second axis. |
| 2391 | +
|
| 2392 | + >>> x = np.arange(8.0).reshape(2, 2, 2) |
| 2393 | + >>> x |
| 2394 | + array([[[ 0., 1.], |
| 2395 | + [ 2., 3.]], |
| 2396 | + [[ 4., 5.], |
| 2397 | + [ 6., 7.]]]) |
| 2398 | + >>> np.hsplit(x, 2) |
| 2399 | + [array([[[ 0., 1.]], |
| 2400 | + [[ 4., 5.]]]), |
| 2401 | + array([[[ 2., 3.]], |
| 2402 | + [[ 6., 7.]]])] |
| 2403 | +
|
| 2404 | + If ``ary`` has one dimension, 'axis' = 0. |
| 2405 | + >>> x = np.arange(4) |
| 2406 | + array([0., 1., 2., 3.]) |
| 2407 | + >>> np.hsplit(x, 2) |
| 2408 | + [array([0., 1.]), array([2., 3.])] |
| 2409 | +
|
| 2410 | + If you want to produce an empty sub-array, you can see an example. |
| 2411 | + >>> np.hsplit(x, [2, 2]) |
| 2412 | + [array([0., 1.]), array([], dtype=float32), array([2., 3.])] |
| 2413 | + """ |
| 2414 | + indices = [] |
| 2415 | + axis = 1 |
| 2416 | + if (len(ary.shape) == 1): |
| 2417 | + axis = 0 |
| 2418 | + axis_size = ary.shape[axis] |
| 2419 | + if isinstance(indices_or_sections, int): |
| 2420 | + sections = indices_or_sections |
| 2421 | + if axis_size % sections: |
| 2422 | + raise ValueError('array hsplit does not result in an equal division') |
| 2423 | + section_size = int(axis_size / sections) |
| 2424 | + indices = [i * section_size for i in range(sections)] |
| 2425 | + elif isinstance(indices_or_sections, (list, set, tuple)): |
| 2426 | + indices = [0] + list(indices_or_sections) |
| 2427 | + else: |
| 2428 | + raise ValueError('indices_or_sections must either int or tuple of ints') |
| 2429 | + ret = _npi.hsplit(ary, indices, axis, False) |
| 2430 | + if not isinstance(ret, list): |
| 2431 | + raise NotImplementedError('single output from hsplit is not supported yet...') |
| 2432 | + return ret |
| 2433 | +# pylint: enable=redefined-outer-name |
| 2434 | + |
| 2435 | + |
2321 | 2436 | @set_module('mxnet.ndarray.numpy') |
2322 | 2437 | def concatenate(seq, axis=0, out=None): |
2323 | 2438 | """Join a sequence of arrays along an existing axis. |
@@ -3464,3 +3579,49 @@ def hypot(x1, x2, out=None): |
3464 | 3579 | [ 5., 5., 5.]]) |
3465 | 3580 | """ |
3466 | 3581 | return _ufunc_helper(x1, x2, _npi.hypot, _np.hypot, _npi.hypot_scalar, None, out) |
| 3582 | + |
| 3583 | + |
| 3584 | +@set_module('mxnet.ndarray.numpy') |
| 3585 | +def rot90(m, k=1, axes=(0, 1)): |
| 3586 | + """ |
| 3587 | + Rotate an array by 90 degrees in the plane specified by axes. |
| 3588 | + Rotation direction is from the first towards the second axis. |
| 3589 | + Parameters |
| 3590 | + ---------- |
| 3591 | + m : ndarray |
| 3592 | + Array of two or more dimensions. |
| 3593 | + k : integer |
| 3594 | + Number of times the array is rotated by 90 degrees. |
| 3595 | + axes: (2,) array_like |
| 3596 | + The array is rotated in the plane defined by the axes. |
| 3597 | + Axes must be different. |
| 3598 | +
|
| 3599 | + Returns |
| 3600 | + ------- |
| 3601 | + y : ndarray |
| 3602 | + A rotated view of `m`. |
| 3603 | +
|
| 3604 | + ----- |
| 3605 | + rot90(m, k=1, axes=(1,0)) is the reverse of rot90(m, k=1, axes=(0,1)) |
| 3606 | + rot90(m, k=1, axes=(1,0)) is equivalent to rot90(m, k=-1, axes=(0,1)) |
| 3607 | + Examples |
| 3608 | + -------- |
| 3609 | + >>> m = np.array([[1,2],[3,4]], 'int') |
| 3610 | + >>> m |
| 3611 | + array([[1, 2], |
| 3612 | + [3, 4]], dtype=int64) |
| 3613 | + >>> np.rot90(m) |
| 3614 | + array([[2, 4], |
| 3615 | + [1, 3]], dtype=int64) |
| 3616 | + >>> np.rot90(m, 2) |
| 3617 | + array([[4, 3], |
| 3618 | + [2, 1]], dtype=int64) |
| 3619 | + >>> m = np.arange(8).reshape((2,2,2)) |
| 3620 | + >>> np.rot90(m, 1, (1,2)) |
| 3621 | + array([[[1., 3.], |
| 3622 | + [0., 2.]], |
| 3623 | +
|
| 3624 | + [[5., 7.], |
| 3625 | + [4., 6.]]]) |
| 3626 | + """ |
| 3627 | + return _npi.rot90(m, k=k, axes=axes) |
0 commit comments