Questions tagged [mean]

The arithmetic mean (or simply the mean or average when the context is clear) is the central tendency of a collection of numbers. The mean is calculated as the sum of the numbers divided by the size of the collection.

The arithmetic mean, or simply the mean or when the context is clear, is the central tendency of a collection of numbers. The mean is calculated as the sum of the numbers divided by the size of the collection. Besides the arithmetic mean, the geometric mean and the harmonic mean can be calculated as well.

Means apply an equal weight to every member of a collection of numbers. This feature makes means not robust to outlier members. cf.

Source: Wikipedia

3925 questions
36
votes
4 answers

Element-wise mean in R

In R, I have two vectors: a <- c(1, 2, 3, 4) b <- c(NA, 6, 7, 8) How do I find the element-wise mean of the two vectors, removing NA, without a loop? i.e. I want to get the vector of (1, 4, 5, 6) I know the function mean(), I know the argument…
Zhang18
  • 4,800
  • 10
  • 50
  • 67
36
votes
5 answers

typeerror: app.use() requires middleware function

I am learning node.js with express template engine, I am following udemy course "learn node.js by building 10 projects", while following a lecture when professor run npm start localhost:3000 starts while mine pops up error indicating app.use…
mean learner
  • 369
  • 1
  • 3
  • 8
34
votes
6 answers

Middle point of each pair of an numpy.array

I have an array of the form: x = np.array([ 1230., 1230., 1227., 1235., 1217., 1153., 1170.]) and I would like to produce another array where the values are the mean of each pair of values within my original array: xm = np.array([ 1230., …
iury simoes-sousa
  • 1,440
  • 3
  • 20
  • 37
32
votes
2 answers

Numpy mean of nonzero values

I have a matrix of size N*M and I want to find the mean value for each row. The values are from 1 to 5 and entries that do not have any value are set to 0. However, when I want to find the mean using the following method, it gives me the wrong mean…
HimanAB
  • 2,443
  • 8
  • 29
  • 43
31
votes
7 answers

How to use numpy with 'None' value in Python?

I'd like to calculate the mean of an array in Python in this form: Matrice = [1, 2, None] I'd just like to have my None value ignored by the numpy.mean calculation but I can't figure out how to do it.
user330860
29
votes
4 answers

Finding the mean and standard deviation of a timedelta object in pandas df

I would like to calculate the mean and standard deviation of a timedelta by bank from a dataframe with two columns shown below. When I run the code (also shown below) I get the below error: pandas.core.base.DataError: No numeric types to…
Graham Streich
  • 874
  • 3
  • 15
  • 31
28
votes
9 answers

Angular Error: NodeInjector: NOT_FOUND [ControlContainer]

core.js:5873 ERROR Error: NodeInjector: NOT_FOUND [ControlContainer] Sometimes when I restart the project it runs perfectly. There are only changes in app.component.html :
sanjay
  • 514
  • 2
  • 5
  • 14
28
votes
3 answers

Generate random numbers with fixed mean and sd

When generating random numbers in R using rnorm (or runif etc.), they seldom have the exact mean and SD as the distribution they are sampled from. Is there any simple one-or-two-liner that does this for me? As a preliminary solution, I've created…
Jonas Lindeløv
  • 5,442
  • 6
  • 31
  • 54
27
votes
6 answers

Mean of a column in a data frame, given the column's name

I'm inside a big function I have to write. In the last part I have to calculate the mean of a column in a data frame. The name of the column I am operating on is given as an argument to the function.
FranGoitia
  • 1,965
  • 3
  • 30
  • 49
25
votes
7 answers

trying to install bcrypt into node project + node set up issues

I have seen some very similar questions but none that I have found seem to work. I am trying to npm install bcrypt but i keep getting the error below. bycrypt is the command that I use to install bcrypt modules. I do have Xcode and installing…
ReganPerkins
  • 1,645
  • 3
  • 17
  • 36
25
votes
5 answers

Mean by factor by level

Maybe this is simple but I can't find answer on web. I have problem with mean calculation by factors by level. My data looks typicaly: factor, value a,1 a,2 b,1 b,1 b,1 c,1 I want to get vector A contains mean only for level "a" If I type A on…
Bartek Taciak
  • 295
  • 1
  • 3
  • 6
25
votes
5 answers

Mean value and standard deviation of a very huge data set

I am wondering if there is an algorithm that calculates the mean value and standard deviation of an unbound data set. for example, I am monitoring an measurement value, say, electric current. I would like to have the mean value of all historical…
Alfred Zhong
  • 6,773
  • 11
  • 47
  • 59
24
votes
6 answers

How to catch the error when inserting a MongoDB document which violates an unique index?

I'm building a MEAN app. This is my Username schema, the username should be unique. var mongoose = require('mongoose'); var Schema = mongoose.Schema; module.exports = mongoose.model('User', new Schema({ username: { type: String, unique: true…
Hiero
  • 2,182
  • 7
  • 28
  • 47
21
votes
3 answers

Get mean of 2D slice of a 3D array in numpy

I have a numpy array with a shape of: (11L, 5L, 5L) I want to calculate the mean over the 25 elements of each 'slice' of the array [0, :, :], [1, :, :] etc, returning 11 values. It seems silly, but I can't work out how to do this. I've thought the…
robintw
  • 27,571
  • 51
  • 138
  • 205
20
votes
3 answers

How to find the average of the differences between all the numbers of a Python List

I have a python list like this, arr = [110, 60, 30, 10, 5] What I need to do is actually find the difference of every number with all the other numbers and then find the average of all those differences. So, for this case, it would first find the…
Asad Hussain
  • 564
  • 2
  • 15