|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 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 | +# midrange |
| 22 | + |
| 23 | +> Compute the [mid-range][mid-range] of a one-dimensional ndarray. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +The [**mid-range**][mid-range], or **mid-extreme**, is the arithmetic mean of the maximum and minimum values in a data set. The measure is the midpoint of the range and a measure of central tendency. |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<section class="usage"> |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +```javascript |
| 38 | +var midrange = require( '@stdlib/stats/base/ndarray/midrange' ); |
| 39 | +``` |
| 40 | + |
| 41 | +#### midrange( arrays ) |
| 42 | + |
| 43 | +Computes the [mid-range][mid-range] of a one-dimensional ndarray. |
| 44 | + |
| 45 | +```javascript |
| 46 | +var ndarray = require( '@stdlib/ndarray/base/ctor' ); |
| 47 | + |
| 48 | +var xbuf = [ 1.0, 2.0, 5.0, 10.0 ]; |
| 49 | +var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); |
| 50 | + |
| 51 | +var v = midrange( [ x ] ); |
| 52 | +// returns 5.5 |
| 53 | +``` |
| 54 | + |
| 55 | +The function has the following parameters: |
| 56 | + |
| 57 | +- **arrays**: array-like object containing a one-dimensional input ndarray. |
| 58 | + |
| 59 | +</section> |
| 60 | + |
| 61 | +<!-- /.usage --> |
| 62 | + |
| 63 | +<section class="notes"> |
| 64 | + |
| 65 | +## Notes |
| 66 | + |
| 67 | +- If provided an empty one-dimensional ndarray, the function returns `NaN`. |
| 68 | + |
| 69 | +</section> |
| 70 | + |
| 71 | +<!-- /.notes --> |
| 72 | + |
| 73 | +<section class="examples"> |
| 74 | + |
| 75 | +## Examples |
| 76 | + |
| 77 | +<!-- eslint no-undef: "error" --> |
| 78 | + |
| 79 | +```javascript |
| 80 | +var uniform = require( '@stdlib/random/array/uniform' ); |
| 81 | +var ndarray = require( '@stdlib/ndarray/base/ctor' ); |
| 82 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 83 | +var midrange = require( '@stdlib/stats/base/ndarray/midrange' ); |
| 84 | + |
| 85 | +var xbuf = uniform( 10, -50.0, 50.0, { |
| 86 | + 'dtype': 'generic' |
| 87 | +}); |
| 88 | +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); |
| 89 | +console.log( ndarray2array( x ) ); |
| 90 | + |
| 91 | +var v = midrange( [ x ] ); |
| 92 | +console.log( v ); |
| 93 | +``` |
| 94 | + |
| 95 | +</section> |
| 96 | + |
| 97 | +<!-- /.examples --> |
| 98 | + |
| 99 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 100 | + |
| 101 | +<section class="related"> |
| 102 | + |
| 103 | +</section> |
| 104 | + |
| 105 | +<!-- /.related --> |
| 106 | + |
| 107 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 108 | + |
| 109 | +<section class="links"> |
| 110 | + |
| 111 | +[mid-range]: https://en.wikipedia.org/wiki/Mid-range |
| 112 | + |
| 113 | +</section> |
| 114 | + |
| 115 | +<!-- /.links --> |
0 commit comments