Calculate the mid-range of an array according to a mask.
The mid-range is defined as 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 mskmidrange = require( '@stdlib/stats/array/mskmidrange' );Computes the mid-range of an array according to a mask.
var x = [ 1.0, -2.0, 4.0, 2.0 ];
var mask = [ 0, 0, 1, 0 ];
var v = mskmidrange( x, mask );
// returns 0.0The function has the following parameters:
- x: input array.
- mask: mask array. If a
maskarray element is0, the corresponding element inxis considered valid and included in computation. If amaskarray element is1, the corresponding element inxis considered invalid/missing and excluded from computation.
- If provided an empty array, the function returns
NaN. - The function supports array-like objects having getter and setter accessors for array element access (e.g.,
@stdlib/array/base/accessor).
var uniform = require( '@stdlib/random/array/uniform' );
var bernoulli = require( '@stdlib/random/array/bernoulli' );
var mskmidrange = require( '@stdlib/stats/array/mskmidrange' );
var x = uniform( 10, -50.0, 50.0, {
'dtype': 'float64'
});
console.log( x );
var mask = bernoulli( x.length, 0.2, {
'dtype': 'uint8'
});
console.log( mask );
var v = mskmidrange( x, mask );
console.log( v );