Questions tagged [average]

In mathematics, an average is a measure of the "middle" or "typical" value of a data set. Different types of averages include the arithmetic mean, the median, and the mode.

In the most common case, the data set is a list of numbers. The average of a list of numbers is a single number intended to typify the numbers in the list. If all the numbers in the list are the same, then this number should be used. If the numbers are not the same, the average is calculated by combining the numbers from the list in a specific way and computing a single number as being the average of the list.

Many different descriptive statistics can be chosen as a measure of the central tendency of the data items. These include the arithmetic mean, the median, and the mode. Other statistics, such as the standard deviation and the range, are called measures of spread and describe how spread out the data is.

See also: , ,

5780 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
280
votes
35 answers

How to compute the sum and average of elements in an array?

I am having problems adding all the elements of an array as well as averaging them out. How would I do this and implement it with the code I currently have? The elements are supposed to be defined as I have it below.
jonathan miller
  • 2,919
  • 2
  • 14
  • 6
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
91
votes
3 answers

Averaging over every n elements of a numpy array

I have a numpy array. I want to create a new array which is the average over every consecutive triplet of elements. So the new array will be a third of the size as the original. As an example: np.array([1,2,3,1,2,3,1,2,3]) should return the…
user1654183
  • 4,375
  • 6
  • 26
  • 33
81
votes
4 answers

How to find average from array in php?

Example: $a[] = '56'; $a[] = '66'; $a[] = ''; $a[] = '58'; $a[] = '85'; $a[] = ''; $a[] = ''; $a[] = '76'; $a[] = ''; $a[] = '57'; Actually how to find average value from this array excluding empty. please help to resolve this problem.
Dinesh G
  • 1,325
  • 4
  • 17
  • 24
71
votes
11 answers

Calculating average of an array list?

I'm trying to use the below code to calculate the average of a set of values that a user enters and display it in a jTextArea but it does not work properly. Say, a user enters 7, 4, and 5, the program displays 1 as the average when it should display…
user1419306
  • 779
  • 2
  • 6
  • 10
66
votes
3 answers

How to efficiently compute average on the fly (moving average)?

I come up with this n=1; curAvg = 0; loop{ curAvg = curAvg + (newNum - curAvg)/n; n++; } I think highlights of this way are: - It avoids big numbers (and possible overflow if you would sum and then divide) - you save one register (not need to…
Vit Bernatik
  • 3,566
  • 2
  • 34
  • 40
62
votes
7 answers

Finding moving average from data points in Python

I am playing in Python a bit again, and I found a neat book with examples. One of the examples is to plot some data. I have a .txt file with two columns and I have the data. I plotted the data just fine, but in the exercise it says: Modify your…
dingo_d
  • 11,160
  • 11
  • 73
  • 132
60
votes
3 answers

Find average of collection of TimeSpans

I have collection of TimeSpans, they represent time spent doing a task. Now I would like to find the average time spent on that task. It should be easy but for some reason I'm not getting the correct average. Here's my code: private TimeSpan?…
hs2d
  • 6,027
  • 24
  • 64
  • 103
57
votes
8 answers

Exponential Moving Average Sampled at Varying Times

I have a continuous value for which I'd like to calculate an exponential moving average. Normally I'd just use the standard formula for this: Sn = αY + (1-α)Sn-1 where Sn is the new average, α is the alpha, Y is the sample, and Sn-1 is the…
cjs
  • 25,752
  • 9
  • 89
  • 101
54
votes
1 answer

Trying to get the average of a count resultset

I have the following SQL:(bitemp) SELECT COUNT (*) AS Count FROM Table T WHERE (T.Update_time = (SELECT MAX (B.Update_time ) FROM Table B WHERE (B.Id = T.Id)) GROUP BY T.Grouping now I am getting a resultset…
Xavjer
  • 8,838
  • 2
  • 22
  • 42
48
votes
3 answers

Calculate average of column from MYSQL query

I've got a table that I am trying to calculate the average of the values in a column. Here is my lookup: SELECT SUM(P1_Score) AS value_sum FROM tblMatches Where P1_ID LIKE $playerID Any idea how I can determine the average (sum of values / total…
DoubleA
  • 736
  • 1
  • 7
  • 23
48
votes
1 answer

Mysql Average on time column?

SELECT avg( duration ) as average FROM login; The datatype for duration is "time", thus my value is like: 00:00:14, 00:20:23 etc I execute the query it gives me: 2725.78947368421 What is that? I want in time format, can mysql do the average on…
mysqllearner
  • 13,523
  • 15
  • 43
  • 43
39
votes
4 answers

Calculating the averages for each KEY in a Pairwise (K,V) RDD in Spark with Python

I want to share this particular Apache Spark with Python solution because documentation for it is quite poor. I wanted to calculate the average value of K/V pairs (stored in a Pairwise RDD), by KEY. Here is what the sample data looks like: >>>…
NYCeyes
  • 5,215
  • 6
  • 57
  • 64
39
votes
3 answers

SQL query with avg and group by

I have some problems with writing a SQL query for MySQL. I have a table with the following structure: mysql> select id, pass, val from data_r1 limit 10; +------------+--------------+----------------+ | id | pass | val …
theFen
  • 505
  • 1
  • 4
  • 6
1
2 3
99 100