Calculate the maximum value of an array according to a mask.
var mskmax = require( '@stdlib/stats/array/mskmax' );
Computes the maximum value 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 = mskmax( x, mask );
// returns 2.0
The function has the following parameters:
- x: input array.
- mask: mask array. If a
mask
array element is0
, the corresponding element inx
is considered valid and included in computation. If amask
array element is1
, the corresponding element inx
is 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 mskmax = require( '@stdlib/stats/array/mskmax' );
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 = mskmax( x, mask );
console.log( v );