@stdlib/stats-base-ndarray-mskmidrange
v0.1.1
Published
Calculate the mid-range of a one-dimensional ndarray according to a mask.
Readme
mskmidrange
Calculate the mid-range of a one-dimensional ndarray according to a mask.
The 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.
Installation
npm install @stdlib/stats-base-ndarray-mskmidrangeUsage
var mskmidrange = require( '@stdlib/stats-base-ndarray-mskmidrange' );mskmidrange( arrays )
Computes the mid-range of a one-dimensional ndarray according to a mask.
var ndarray = require( '@stdlib/ndarray-base-ctor' );
var xbuf = [ 1.0, -2.0, 4.0, 2.0 ];
var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
var maskbuf = [ 0, 0, 1, 0 ];
var mask = new ndarray( 'generic', maskbuf, [ 4 ], [ 1 ], 0, 'row-major' );
var v = mskmidrange( [ x, mask ] );
// returns 0.0The function has the following parameters:
- arrays: array-like object containing a one-dimensional input ndarray and a one-dimensional mask ndarray.
Notes
- If a mask array element is
0, the corresponding element in the input ndarray is considered valid and included in computation. If a mask array element is1, the corresponding element in the input ndarray is considered invalid/missing and excluded from computation. - If provided an empty ndarray or a mask with all elements set to
1, the function returnsNaN.
Examples
var uniform = require( '@stdlib/random-array-uniform' );
var bernoulli = require( '@stdlib/random-array-bernoulli' );
var ndarray = require( '@stdlib/ndarray-base-ctor' );
var ndarray2array = require( '@stdlib/ndarray-to-array' );
var mskmidrange = require( '@stdlib/stats-base-ndarray-mskmidrange' );
var xbuf = uniform( 10, -50.0, 50.0, {
'dtype': 'generic'
});
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
console.log( ndarray2array( x ) );
var maskbuf = bernoulli( xbuf.length, 0.2, {
'dtype': 'uint8'
});
var mask = new ndarray( 'uint8', maskbuf, [ maskbuf.length ], [ 1 ], 0, 'row-major' );
console.log( ndarray2array( mask ) );
var v = mskmidrange( [ x, mask ] );
console.log( v );Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
