You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Licensed under the Apache License, Version 2.0 (the "License");
210
+
* you may not use this file except in compliance with the License.
211
+
* You may obtain a copy of the License at
212
+
*
213
+
* http://www.apache.org/licenses/LICENSE-2.0
214
+
*
215
+
* Unless required by applicable law or agreed to in writing, software
216
+
* distributed under the License is distributed on an "AS IS" BASIS,
217
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
218
+
* See the License for the specific language governing permissions and
219
+
* limitations under the License.
220
+
*/
221
+
222
+
'use strict';
223
+
224
+
// MODULES //
225
+
226
+
var isCollection = require( '@stdlib/assert/is-collection' );
227
+
var dtypes = require( '@stdlib/array/dtypes' );
228
+
var dtype = require( '@stdlib/array/dtype' );
229
+
var contains = require( '@stdlib/array/base/assert/contains' );
230
+
var join = require( '@stdlib/array/base/join' );
231
+
var strided = require( '@stdlib/stats/base/mean' ).ndarray;
232
+
var format = require( '@stdlib/string/format' );
233
+
234
+
235
+
// VARIABLES //
236
+
237
+
var IDTYPES = dtypes( 'real_and_generic' );
238
+
var GENERIC_DTYPE = 'generic';
239
+
240
+
241
+
// MAIN //
242
+
243
+
/**
244
+
* Computes the arithmetic mean of an array.
245
+
*
246
+
* @param {NumericArray} x - input array
247
+
* @throws {TypeError} first argument must be an array-like object
248
+
* @throws {TypeError} first argument must have a supported data type
249
+
* @returns {number} arithmetic mean
250
+
*
251
+
* @example
252
+
* var x = [ 1.0, -2.0, 2.0 ];
253
+
*
254
+
* var v = mean( x );
255
+
* // returns ~0.3333
256
+
*/
257
+
function mean( x ) {
258
+
var dt;
259
+
if ( !isCollection( x ) ) {
260
+
throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );
261
+
}
262
+
dt = dtype( x ) || GENERIC_DTYPE;
263
+
if ( !contains( IDTYPES, dt ) ) {
264
+
throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Data type: `%s`.', join( IDTYPES, '", "' ), dt ) );
265
+
}
266
+
return strided( x.length, x, 1, 0 );
267
+
}
268
+
269
+
270
+
// EXPORTS //
271
+
272
+
module.exports = mean;
273
+
</pre></td></tr></table></pre>
274
+
275
+
<divclass='push'></div><!-- for sticky footer -->
276
+
</div><!-- /wrapper -->
277
+
<divclass='footer quiet pad2 space-top1 center small'>
0 commit comments