@stdlib/stats-base-ndarray-mskmaxabs
v0.1.1
Published
Calculate the maximum absolute value of a one-dimensional ndarray according to a mask.
Readme
mskmaxabs
Calculate the maximum absolute value of a one-dimensional ndarray according to a mask.
Installation
npm install @stdlib/stats-base-ndarray-mskmaxabsUsage
var mskmaxabs = require( '@stdlib/stats-base-ndarray-mskmaxabs' );mskmaxabs( arrays )
Computes the maximum absolute value of a one-dimensional ndarray according to a mask.
var ndarray = require( '@stdlib/ndarray-base-ctor' );
var xbuf = [ 1.0, -5.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 = mskmaxabs( [ x, mask ] );
// returns 5.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 mskmaxabs = require( '@stdlib/stats-base-ndarray-mskmaxabs' );
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 = mskmaxabs( [ 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.
