Compute the arithmetic mean of a one-dimensional single-precision floating-point ndarray using a two-pass error correction algorithm.
npm install @stdlib/stats-base-ndarray-smeanpnWe believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js. The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases. When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there. To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
About stdlib...
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url]
> Compute the [arithmetic mean][arithmetic-mean] of a one-dimensional single-precision floating-point ndarray using a two-pass error correction algorithm.
The [arithmetic mean][arithmetic-mean] is defined as
``bash`
npm install @stdlib/stats-base-ndarray-smeanpn
`javascript`
var smeanpn = require( '@stdlib/stats-base-ndarray-smeanpn' );
#### smeanpn( arrays )
Computes the [arithmetic mean][arithmetic-mean] of a one-dimensional single-precision floating-point ndarray using a two-pass error correction algorithm.
`javascript
var Float32Array = require( '@stdlib/array-float32' );
var ndarray = require( '@stdlib/ndarray-base-ctor' );
var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] );
var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
var v = smeanpn( [ x ] );
// returns 2.5
`
The function has the following parameters:
- arrays: array-like object containing a one-dimensional input ndarray.
- If provided an empty one-dimensional ndarray, the function returns NaN.
`javascript
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var ndarray = require( '@stdlib/ndarray-base-ctor' );
var ndarray2array = require( '@stdlib/ndarray-to-array' );
var smeanpn = require( '@stdlib/stats-base-ndarray-smeanpn' );
var xbuf = discreteUniform( 10, -50, 50, {
'dtype': 'float32'
});
var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
console.log( ndarray2array( x ) );
var v = smeanpn( [ x ] );
console.log( v );
`
*
- Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958][@neely:1966a].
- Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036][@schubert:2018a].
*
This package is part of [stdlib][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][stdlib], see the main project [repository][stdlib].
#### Community
[![Chat][chat-image]][chat-url]
---
See [LICENSE][stdlib-license].
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-ndarray-smeanpn.svg
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-ndarray-smeanpn
[test-image]: https://github.com/stdlib-js/stats-base-ndarray-smeanpn/actions/workflows/test.yml/badge.svg?branch=v0.1.1
[test-url]: https://github.com/stdlib-js/stats-base-ndarray-smeanpn/actions/workflows/test.yml?query=branch:v0.1.1
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-ndarray-smeanpn/main.svg
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-ndarray-smeanpn?branch=main
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
[chat-url]: https://stdlib.zulipchat.com
[stdlib]: https://github.com/stdlib-js/stdlib
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
[umd]: https://github.com/umdjs/umd
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
[deno-url]: https://github.com/stdlib-js/stats-base-ndarray-smeanpn/tree/deno
[deno-readme]: https://github.com/stdlib-js/stats-base-ndarray-smeanpn/blob/deno/README.md
[umd-url]: https://github.com/stdlib-js/stats-base-ndarray-smeanpn/tree/umd
[umd-readme]: https://github.com/stdlib-js/stats-base-ndarray-smeanpn/blob/umd/README.md
[esm-url]: https://github.com/stdlib-js/stats-base-ndarray-smeanpn/tree/esm
[esm-readme]: https://github.com/stdlib-js/stats-base-ndarray-smeanpn/blob/esm/README.md
[branches-url]: https://github.com/stdlib-js/stats-base-ndarray-smeanpn/blob/main/branches.md
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/stats-base-ndarray-smeanpn/main/LICENSE
[arithmetic-mean]: https://en.wikipedia.org/wiki/Arithmetic_mean
[@neely:1966a]: https://doi.org/10.1145/365719.365958
[@schubert:2018a]: https://doi.org/10.1145/3221269.3223036