@stdlib/math-array-special-abs
v0.1.1
Published
Compute the absolute value for each element in an input array.
Readme
abs
Compute the absolute value for each element in an input array.
Installation
npm install @stdlib/math-array-special-absUsage
var abs = require( '@stdlib/math-array-special-abs' );abs( x[, options] )
Computes the absolute value for each element in an input array.
var v = abs( [ -1.0, 2.0, -3.0, 4.0 ] );
// returns [ 1.0, 2.0, 3.0, 4.0 ]The function has the following parameters:
- x: input array.
- options: function options.
The function accepts the following options:
- dtype: output array data type.
To specify the output array data type, set the dtype option.
var v = abs( [ -1.0, 2.0, -3.0, 4.0 ], {
'dtype': 'float64'
});
// returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]abs.assign( x, out )
Computes the absolute value for each element in an input array and assigns results to a provided output array.
var zeros = require( '@stdlib/array-zeros' );
var out = zeros( 4, 'float64' );
// returns <Float64Array>[ 0.0, 0.0, 0.0, 0.0 ]
var v = abs.assign( [ -1.0, 2.0, -3.0, 4.0 ], out );
// returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
var bool = ( v === out );
// returns trueThe method has the following parameters:
- x: input array.
- out: output array.
Examples
var uniform = require( '@stdlib/random-array-uniform' );
var logEach = require( '@stdlib/console-log-each' );
var abs = require( '@stdlib/math-array-special-abs' );
// Generate an array of random numbers:
var x = uniform( 10, -1.0, 1.0, {
'dtype': 'generic'
});
// Perform element-wise computation:
var y = abs( x );
// Print the results:
logEach( 'abs(%f) = %f', x, y );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.
