Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

nanmskrange

Calculate the range of an array according to a mask, ignoring NaN values.

The range is defined as the difference between the maximum and minimum values.

Usage

var nanmskrange = require( '@stdlib/stats/array/nanmskrange' );

nanmskrange( x, mask )

Computes the range of an array according to a mask, ignoring NaN values.

var x = [ 1.0, -2.0, 4.0, 2.0, NaN, NaN ];
var mask = [ 0, 0, 1, 0, 0, 0 ];

var v = nanmskrange( x, mask );
// returns 4.0

The function has the following parameters:

  • x: input array.
  • mask: mask array. If a mask array element is 0, the corresponding element in x is considered valid and included in computation. If a mask array element is 1, the corresponding element in x is considered invalid/missing and excluded from computation.

Notes

  • 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).

Examples

var uniform = require( '@stdlib/random/base/uniform' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var nanmskrange = require( '@stdlib/stats/array/nanmskrange' );

function rand() {
    if ( bernoulli( 0.8 ) < 1 ) {
        return NaN;
    }
    return uniform( -50.0, 50.0 );
}

var x = filledarrayBy( 10, 'float64', rand );
console.log( x );

var mask = filledarrayBy( x.length, 'uint8', bernoulli.factory( 0.2 ) );
console.log( mask );

var v = nanmskrange( x, mask );
console.log( v );