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
20
votes
5 answers

z-Scores(standard deviation and mean) in PHP

I am trying to calculate Z-scores using PHP. Essentially, I am looking for the most efficient way to calculate the mean and standard deviation of a data set (PHP array). Any suggestions on how to do this in PHP? I am trying to do this in the…
Spencer
  • 21,348
  • 34
  • 85
  • 121
19
votes
4 answers

Failed to execute 'open' on 'XMLHttpRequest': Invalid URL

I got run time error: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL Error: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL at http://localhost:8100/build/polyfills.js:3:2793 at XMLHttpRequest.open…
rupesh sripuram
  • 279
  • 1
  • 3
  • 12
19
votes
1 answer

how to calculate and use cvMat mean value

In the openCV cheat sheet (C++), I have found the matrix opration mean(). When I use it: float myMatMean = mean( MyMat ); I get the error: no suitable conversion function from "cv::Scalar" to "float" exists What can I do in order to use this…
EyalG
  • 1,193
  • 3
  • 10
  • 11
19
votes
4 answers

harmonic mean in python

The Harmonic Mean function in Python (scipy.stats.hmean) requires that the input be positive numbers. For example: from scipy import stats print stats.hmean([ -50.2 , 100.5 ]) results in: ValueError: Harmonic mean only defined if all elements…
Zach
  • 4,624
  • 13
  • 43
  • 60
18
votes
3 answers

How to get the mean of rows of a matrix in Octave?

>> a = [2,3,4;6,7,8] a = 2 3 4 6 7 8 >> mean(a) ans = 4 5 6 where [4 5 6] is the mean for each column How can I get the mean for each row? In my example, I would expect [3;7]
B Seven
  • 44,484
  • 66
  • 240
  • 385
18
votes
10 answers

compute mean in python for a generator

I'm doing some statistics work, I have a (large) collection of random numbers to compute the mean of, I'd like to work with generators, because I just need to compute the mean, so I don't need to store the numbers. The problem is that numpy.mean…
nick maxwell
  • 1,441
  • 3
  • 16
  • 22
17
votes
5 answers

pd.rolling_mean becoming deprecated - alternatives for ndarrays

EDIT: This question was asked in 2016 and similar questions have been posted on SO years later after the functionality was finally removed, e.g. module 'pandas' has no attribute 'rolling_mean' However, the question concerns performance of the new…
saladi
  • 3,103
  • 6
  • 36
  • 61
17
votes
2 answers

Mean over multiple axis in NumPy

I Want to write the code below as Pythonic way, applying mean over two axis. What the best way to do this? import numpy as np m = np.random.rand(30, 10, 10) m_mean = np.zeros((30, 1)) for j in range(30): m_mean[j, 0] = m[j, :, :].mean()
17
votes
5 answers

how to calculate mean/median per group in a dataframe in r

I have a dataframe recording how much money a costomer spend in detail like the following: custid, value 1, 1 1, 3 1, 2 1, 5 1, 4 1, 1 2, 1 2, 10 3, 1 3, 2 3, 5 How to calcuate the charicteristics using mean,max,median,std, etc like the…
Daniel Wu
  • 5,853
  • 12
  • 42
  • 93
16
votes
3 answers

Counting average on list field

I have list of A, and I want to count average on it's field a. What's the best way to do it? class A { int a; int b; } void f() { var L = new List(); for (int i=0; i<3; i++) { L.Add(new A(){a = i}); } }
Nihau
  • 306
  • 1
  • 1
  • 8
15
votes
2 answers

How to add mean, and mode to ggplot histogram?

I need to add a mean line and the value of the mode for example to this kinds of plots: I use this for calculate the number of bins: bw <- diff(range(cars$lenght)) / (2 * IQR(cars$lenght) / length(cars$lenght)^(1/3)) And the…
Borja_042
  • 1,071
  • 1
  • 14
  • 26
15
votes
2 answers

Subtract every column in dataframe with the mean of that column with Python

I am looking for a way to find means of each column in a python dataframe and subtract that column with the mean of that column. Suppose I have: df = pd.DataFrame({'a': [1.5, 2.5], 'b': [0.25, 2.75], 'c': [1.25, 0.75]}) I want to find the mean of…
haimen
  • 1,985
  • 7
  • 30
  • 53
14
votes
6 answers

Pandas dataframe conditional mean based on column names

It will be the easiest to explain starting with a sample of the dataframe: TimeStamp 382.098 382.461 383.185 383.548 10:28:00 0.012448 0.012362 0.0124485 0.012362 10:30:00 0.0124135 0.0123965 0.0124135 …
Brain_overflowed
  • 426
  • 1
  • 5
  • 21
14
votes
6 answers

Swift Array extension for standard deviation

I am frequently needing to calculate mean and standard deviation for numeric arrays. So I've written a small protocol and extensions for numeric types that seems to work. I just would like feedback if there is anything wrong with how I have done…
twiz_
  • 1,178
  • 10
  • 16
14
votes
5 answers

Python/Pandas Dataframe replace 0 with median value

I have a python pandas dataframe with several columns and one column has 0 values. I want to replace the 0 values with the median or mean of this column. data is my dataframe artist_hotness is the column mean_artist_hotness =…
jeangelj
  • 4,338
  • 16
  • 54
  • 98