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
667
votes
24 answers

Finding the average of a list

How do I find the mean average of a list in Python? [1, 2, 3, 4] ⟶ 2.5
Carla Dessi
  • 9,086
  • 9
  • 39
  • 53
278
votes
13 answers

Calculating arithmetic mean (one type of average) in Python

Is there a built-in or standard library method in Python to calculate the arithmetic mean (one type of average) of a list of numbers?
jrdioko
  • 32,230
  • 28
  • 81
  • 120
257
votes
5 answers

np.mean() vs np.average() in Python NumPy?

I notice that In [30]: np.mean([1, 2, 3]) Out[30]: 2.0 In [31]: np.average([1, 2, 3]) Out[31]: 2.0 However, there should be some differences, since after all they are two different functions. What are the differences between them?
Sibbs Gambling
  • 19,274
  • 42
  • 103
  • 174
128
votes
3 answers

group by in group by and average

I have a dataframe like this: cluster org time 1 a 8 1 a 6 2 h 34 1 c 23 2 d 74 3 w 6 I would like to calculate the average of time per org per…
UserYmY
  • 8,034
  • 17
  • 57
  • 71
110
votes
7 answers

Mean Squared Error in Numpy?

Is there a method in numpy for calculating the Mean Squared Error between two matrices? I've tried searching but found none. Is it under a different name? If there isn't, how do you overcome this? Do you write it yourself or use a different lib?
TheMeaningfulEngineer
  • 15,679
  • 27
  • 85
  • 143
104
votes
10 answers

Calculate mean and standard deviation from a vector of samples in C++ using Boost

Is there a way to calculate mean and standard deviation for a vector containing samples using Boost? Or do I have to create an accumulator and feed the vector into it?
user393144
  • 1,575
  • 3
  • 14
  • 21
104
votes
3 answers

What is the difference between np.mean and tf.reduce_mean?

In the MNIST beginner tutorial, there is the statement accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) tf.cast basically changes the type of tensor the object is, but what is the difference between tf.reduce_mean and np.mean? Here…
O.rka
  • 29,847
  • 68
  • 194
  • 309
103
votes
3 answers

Calculate mean across dimension in a 2D array

I have an array a like this: a = [[40, 10], [50, 11]] I need to calculate the mean for each dimension separately, the result should be this: [45, 10.5] 45 being the mean of a[*][0] and 10.5 the mean of a[*][1]. What is the most elegant way of…
otmezger
  • 10,410
  • 21
  • 64
  • 90
78
votes
3 answers

express app server . listen all interfaces instead of localhost only

I'm very new for this stuff, and trying to make some express app var express = require('express'); var app = express(); app.listen(3000, function(err) { if(err){ console.log(err); } else { console.log("listen:3000"); …
Pavel L
  • 1,857
  • 3
  • 17
  • 23
71
votes
10 answers

calculate the mean for each column of a matrix in R

I am working on R in R studio. I need to calculate the mean for each column of a data frame. cluster1 // 5 by 4 data frame mean(cluster1) // I got : Warning message: In mean.default(cluster1) : argument is not numeric or logical:…
user2420472
  • 1,127
  • 1
  • 12
  • 20
55
votes
6 answers

Why is statistics.mean() so slow?

I compared the performance of the mean function of the statistics module with the simple sum(l)/len(l) method and found the mean function to be very slow for some reason. I used timeit with the two code snippets below to compare them, does anyone…
Just some guy
  • 1,909
  • 4
  • 21
  • 32
51
votes
9 answers

How to efficiently get the mean of the elements in two list of lists in Python

I have two lists as follows. mylist1 = [["lemon", 0.1], ["egg", 0.1], ["muffin", 0.3], ["chocolate", 0.5]] mylist2 = [["chocolate", 0.5], ["milk", 0.2], ["carrot", 0.8], ["egg", 0.8]] I want to get the mean of the common elements in the two lists…
EmJ
  • 4,398
  • 9
  • 44
  • 105
45
votes
4 answers

Calculate group mean, sum, or other summary stats. and assign column to original data

I want to calculate mean (or any other summary statistics of length one, e.g. min, max, length, sum) of a numeric variable ("value") within each level of a grouping variable ("group"). The summary statistic should be assigned to a new variable which…
Mike
  • 761
  • 2
  • 7
  • 5
42
votes
2 answers

Add a row with means of columns to pandas DataFrame

I have a pandas DataFrame consisting of some sensor readings taken over time like this: diode1 diode2 diode3 diode4 Time 0.530 7 0 10 16 1.218 17 7 14 19 1.895 13 8 16 …
willk
  • 3,727
  • 2
  • 27
  • 44
40
votes
6 answers

Calculating weighted mean and standard deviation

I have a time series x_0 ... x_t. I would like to compute the exponentially weighted variance of the data. That is: V = SUM{w_i*(x_i - x_bar)^2, i=1 to T} where SUM{w_i} = 1 and x_bar=SUM{w_i*x_i} ref:…
Alex
  • 19,533
  • 37
  • 126
  • 195
1
2 3
99 100