|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# toReversedDimensions |
| 22 | + |
| 23 | +> Return a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var toReversedDimensions = require( '@stdlib/ndarray/base/to-reversed-dimensions' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### toReversedDimensions( x, dims ) |
| 44 | + |
| 45 | +Returns a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var array = require( '@stdlib/ndarray/array' ); |
| 49 | + |
| 50 | +var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ); |
| 51 | +// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] |
| 52 | + |
| 53 | +var y = toReversedDimensions( x, [ 0, 1 ] ); |
| 54 | +// returns <ndarray>[ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] |
| 55 | +``` |
| 56 | + |
| 57 | +The function accepts the following arguments: |
| 58 | + |
| 59 | +- **x**: input ndarray. |
| 60 | +- **dims**: dimension indices along which to reverse elements. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. |
| 61 | + |
| 62 | +</section> |
| 63 | + |
| 64 | +<!-- /.usage --> |
| 65 | + |
| 66 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 67 | + |
| 68 | +<section class="notes"> |
| 69 | + |
| 70 | +</section> |
| 71 | + |
| 72 | +<!-- /.notes --> |
| 73 | + |
| 74 | +<!-- Package usage examples. --> |
| 75 | + |
| 76 | +<section class="examples"> |
| 77 | + |
| 78 | +## Examples |
| 79 | + |
| 80 | +<!-- eslint no-undef: "error" --> |
| 81 | + |
| 82 | +```javascript |
| 83 | +var array = require( '@stdlib/ndarray/array' ); |
| 84 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 85 | +var toReversedDimensions = require( '@stdlib/ndarray/base/to-reversed-dimensions' ); |
| 86 | + |
| 87 | +// Create a 3x2 matrix: |
| 88 | +var x = array( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] ); |
| 89 | + |
| 90 | +// Reverse the order of the first axis: |
| 91 | +var y = toReversedDimensions( x, [ 0 ] ); |
| 92 | +var arr = ndarray2array( y ); |
| 93 | +// returns [ [ 5, 6 ], [ 3, 4 ], [ 1, 2 ] ] |
| 94 | + |
| 95 | +// Reverse the order of the second axis: |
| 96 | +y = toReversedDimensions( x, [ 1 ] ); |
| 97 | +arr = ndarray2array( y ); |
| 98 | +// returns [ [ 2, 1 ], [ 4, 3 ], [ 6, 5 ] ] |
| 99 | + |
| 100 | +// Reverse the order of all axes: |
| 101 | +y = toReversedDimensions( x, [ 0, 1 ] ); |
| 102 | +arr = ndarray2array( y ); |
| 103 | +// returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] |
| 104 | + |
| 105 | +// Supports negative dimension indices: |
| 106 | +y = toReversedDimensions( x, [ -2, -1 ] ); |
| 107 | +arr = ndarray2array( y ); |
| 108 | +// returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] |
| 109 | +``` |
| 110 | + |
| 111 | +</section> |
| 112 | + |
| 113 | +<!-- /.examples --> |
| 114 | + |
| 115 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 116 | + |
| 117 | +<section class="references"> |
| 118 | + |
| 119 | +</section> |
| 120 | + |
| 121 | +<!-- /.references --> |
| 122 | + |
| 123 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 124 | + |
| 125 | +<section class="related"> |
| 126 | + |
| 127 | +</section> |
| 128 | + |
| 129 | +<!-- /.related --> |
| 130 | + |
| 131 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 132 | + |
| 133 | +<section class="links"> |
| 134 | + |
| 135 | +<!-- <related-links> --> |
| 136 | + |
| 137 | +<!-- </related-links> --> |
| 138 | + |
| 139 | +</section> |
| 140 | + |
| 141 | +<!-- /.links --> |
0 commit comments