Calculate the midrange of a one-dimensional double-precision floating-point ndarray according to a mask, ignoring
NaNvalues.
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.
var dnanmskmidrange = require( '@stdlib/stats/base/ndarray/dnanmskmidrange' );Computes the mid-range of a one-dimensional double-precision floating-point ndarray according to a mask, ignoring NaN values.
var Float64Array = require( '@stdlib/array/float64' );
var Uint8Array = require( '@stdlib/array/uint8' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );
var xbuf = new Float64Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] );
var x = new ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );
var maskbuf = new Uint8Array( [ 0, 0, 1, 0, 0 ] );
var mask = new ndarray( 'uint8', maskbuf, [ 5 ], [ 1 ], 0, 'row-major' );
var v = dnanmskmidrange( [ 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.
- 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.
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 dnanmskmidrange = require( '@stdlib/stats/base/ndarray/dnanmskmidrange' );
var xbuf = uniform( 10, -50.0, 50.0, {
'dtype': 'float64'
});
var x = new ndarray( 'float64', 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 = dnanmskmidrange( [ x, mask ] );
console.log( v );