average

calculate exponential moving average in python

浪子不回头ぞ 提交于 2019-11-27 18:02:02
I have a range of dates and a measurement on each of those dates. I'd like to calculate an exponential moving average for each of the dates. Does anybody know how to do this? I'm new to python. It doesn't appear that averages are built into the standard python library, which strikes me as a little odd. Maybe I'm not looking in the right place. So, given the following code, how could I calculate the moving weighted average of IQ points for calendar dates? from datetime import date days = [date(2008,1,1), date(2008,1,2), date(2008,1,7)] IQ = [110, 105, 90] (there's probably a better way to

TSQL - Average of all values in a column that are not zero

萝らか妹 提交于 2019-11-27 17:20:20
问题 I'm in the process of writing a report and am looking to get the average value of an age column. The problem is that not all rows have an age. If the values for the column are 0 2 4 I would want 3 returned, not 2. I can not simply exclude the zero rows with a WHERE as I'm using using other columns in those rows. Is there such a thing as a AvgIfNotZero type of function? 回答1: SELECT AVG (CASE WHEN Value <> 0 THEN Value ELSE NULL END) .... AVG won't take into account NULL values. Or this AVG

How do I calculate a 3D centroid?

巧了我就是萌 提交于 2019-11-27 16:35:28
问题 Is there even such a thing as a 3D centroid? Let me be perfectly clear—I've been reading and reading about centroids for the last 2 days both on this site and across the web, so I'm perfectly aware at the existing posts on the topic, including Wikipedia. That said, let me explain what I'm trying to do. Basically, I want to take a selection of edges and/or vertices, but NOT faces. Then, I want to place an object at the 3D centroid position. I'll tell you what I don't want: The vertices average

Random number with fixed average

隐身守侯 提交于 2019-11-27 16:14:09
问题 I want to generate 100 random numbers between 1 and 10. But the average of those 100 random numbers should be 7. How can I do that? I am doing as follows: //generating random number Random random = new Random(); int value = random.Next(1,10); And storing each value in an array. If the average of 100 items in the array is not 7 then I need to get another 100 random numbers. Can anyone suggest a better way of doing this? 回答1: Initialize A[0], ..., A[99] to 1 . Initialize I = {0, 1, ..., 99} .

Math average with php

 ̄綄美尐妖づ 提交于 2019-11-27 16:01:08
问题 Time to test your math skills... I'm using php to find the average of $num1, $num2, $num3 and so on; upto an unset amount of numbers. It then saves that average to a database. Next time the php script is called a new number is added to the mix. Is there a math (most likely algebra) equation that I can use to find the average of the original numbers with the new number included. Or do I need to save the original numbers in the database so I can query them and re-calculate the entire bunch of

How to find average from array in php?

允我心安 提交于 2019-11-27 14:35:29
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. first you need to remove empty values, otherwise average will be not accurate. so $a = array_filter($a); $average = array_sum($a)/count($a); echo $average; DEMO More concise and recommended way if(count($a)) { $a = array_filter($a); echo $average = array_sum($a)/count($a); } See here The accepted answer works for the example values, but in general simply using

How to manipulate arrays. Find the average. Beginner Java

ε祈祈猫儿з 提交于 2019-11-27 14:11:06
I have a homework assignment and I was wondering if anyone could help me as I am new to Java and programming and am stuck on a question. The question is: The first method finds the average of the elements of an integer array: public double average(int[] data) That is, given an integer array, data, calculate the average of its elements are return the average value. For example, the average of {1, 3, 2, 5, 8} is 3.8. Here is what I have done so far: public double average(int[] data) { int sum = 0; while(int i=0; i < data.length; i++) sum = sum + data[i]; double average = sum / data.length;;

Find average of collection of TimeSpans

蹲街弑〆低调 提交于 2019-11-27 12:39:35
问题 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? GetTimeSpanAverage(List<TimeSpan> sourceList) { TimeSpan total = default(TimeSpan); var sortedDates = sourceList.OrderBy(x => x); foreach (var dateTime in sortedDates) { total += dateTime; } return TimeSpan.FromMilliseconds(total.TotalMilliseconds

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

你说的曾经没有我的故事 提交于 2019-11-27 10:48:47
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: >>> rdd1.take(10) # Show a small sample. [(u'2013-10-09', 7.60117302052786), (u'2013-10-10', 9.322709163346612), (u'2013-10-10', 28.264462809917358), (u'2013-10-07', 9.664429530201343), (u'2013-10-07', 12.461538461538463), (u'2013-10-09', 20.76923076923077), (u'2013-10-08', 11.842105263157894), (u'2013-10-13', 32.32514177693762), (u'2013-10-13', 26

Exponential Moving Average Sampled at Varying Times

馋奶兔 提交于 2019-11-27 10:44:11
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: S n = αY + (1-α)S n-1 where S n is the new average, α is the alpha, Y is the sample, and S n-1 is the previous average. Unfortunately, due to various issues I don't have a consistent sample time. I may know I can sample at the most, say, once per millisecond, but due to factors out of my control, I may not be able to take a sample for several milliseconds at a time. A likely more common case, however, is that I simple sample a bit early or late: instead