average

average numpy array but retain shape

不问归期 提交于 2020-01-03 08:08:10
问题 I have a Numpy 3 axis array whose elements are 3 dimensional. I'd like to average them and return the same shape of the array. The normal average function removes the 3 dimensions and replace it with the average (as expected): a = np.array([[[0.1, 0.2, 0.3], [0.2, 0.3, 0.4]], [[0.4, 0.4, 0.4], [0.7, 0.6, 0.8]]], np.float32) b = np.average(a, axis=2) # b = [[0.2, 0.3], # [0.4, 0.7]] Result required : # b = [[[0.2, 0.2, 0.2], [0.3, 0.3, 0.3]], # [[0.4, 0.4, 0.4], [0.7, 0.7, 0.7]]] Can you do

Average of a filter of multiple columns in Excel

时光怂恿深爱的人放手 提交于 2020-01-02 16:44:07
问题 I would like a formula to display the average of a number of filtered values in Excel. For example, in column A I have the year, in column B I have the month, and in column C I have the values. So I would like to select the 2011 year, the month of May and get the average of the values in column C that satisfy these requirements. I'm thinking a function like... =AVERAGE(IF(AND($A$1:$A:$100=2011,$B$1:$B:$100=May),$C$1:$C:$100)) But I don't think this will work, and I've tried it. 回答1: Use the

Average of a filter of multiple columns in Excel

。_饼干妹妹 提交于 2020-01-02 16:43:33
问题 I would like a formula to display the average of a number of filtered values in Excel. For example, in column A I have the year, in column B I have the month, and in column C I have the values. So I would like to select the 2011 year, the month of May and get the average of the values in column C that satisfy these requirements. I'm thinking a function like... =AVERAGE(IF(AND($A$1:$A:$100=2011,$B$1:$B:$100=May),$C$1:$C:$100)) But I don't think this will work, and I've tried it. 回答1: Use the

calculate average of y values with different x values

…衆ロ難τιáo~ 提交于 2020-01-02 10:28:49
问题 I tried to calculate the average of y from different arrays such as np.mean(,axis=1) , but with different x values. To produce x and y arrays, I used the code as below: x1=np.arange(10) x2 = np.arange(10)+1 x3 = np.arange(10)+2 x4 = np.arange(10)+3 y1 = x1+1 y2 = x2+2 y3 = x3+3 y4 = x4 +4 The code produces: x1 = [0 1 2 3 4 5 6 7 8 9] x2 = [ 1 2 3 4 5 6 7 8 9 10] x3 = [ 2 3 4 5 6 7 8 9 10 11] x4 = [ 3 4 5 6 7 8 9 10 11 12] y1 = [ 1 2 3 4 5 6 7 8 9 10] y2 = [ 3 4 5 6 7 8 9 10 11 12] y3 = [ 5 6

What's the quickest way to get the mean of a set of numbers from the command line?

喜夏-厌秋 提交于 2020-01-02 00:59:11
问题 Using any tools which you would expect to find on a nix system (in fact, if you want, msdos is also fine too), what is the easiest/fastest way to calculate the mean of a set of numbers, assuming you have them one per line in a stream or file? 回答1: Awk awk '{total += $1; count++ } END {print total/count}' 回答2: awk ' { n += $1 }; END { print n / NR }' This accumulates the sum in n , then divides by the number of items ( NR = Number of Records). Works for integers or reals. 回答3: Using Num-Utils

Aggregating weekly (7 day) data to monthly in R

余生颓废 提交于 2020-01-01 07:11:11
问题 I have data measured over a 7 day period. Part of the data looks as follows: start wk end wk X1 2/1/2004 2/7/2004 89 2/8/2004 2/14/2004 65 2/15/2004 2/21/2004 64 2/22/2004 2/28/2004 95 2/29/2004 3/6/2004 79 3/7/2004 3/13/2004 79 I want to convert this weekly (7 day) data into monthly data using weighted averages of X1. Notice that some of the 7 day X1 data will overlap from one month to the other (X1=79 for the period 2/29 to 3/6 of 2004). Specifically I would obtain the February 2004 monthly

Translate SQL to lambda LINQ with GroupBy and Average

删除回忆录丶 提交于 2020-01-01 04:24:10
问题 I spend a few hours trying to translate simple SQL to lambda LINQ SELECT ID, AVG(Score) FROM myTable GROUP BY ID Any idea? 回答1: from t in myTable group t by new { t.ID } into g select new { Average = g.Average(p => p.Score), g.Key.ID } or Lambda myTable.GroupBy(t => new {ID = t.ID}) .Select (g => new { Average = g.Average (p => p.Score), ID = g.Key.ID }) 回答2: The equivalent in Linq-to-Objects would be something like the below. var results = from row in myTable group row by row.Id into rows

Calculate average or take in an ArrayList as a parameter to a function

 ̄綄美尐妖づ 提交于 2020-01-01 03:43:23
问题 Is there a built-in method to calculate the average of an integer ArrayList? If not, can I make a function that will do that by taking in the name of the ArrayList and returning its average value? 回答1: It's really simple: // Better use a `List`. It is more generic and it also receives an `ArrayList`. public static double average(List<Integer> list) { // 'average' is undefined if there are no elements in the list. if (list == null || list.isEmpty()) return 0.0; // Calculate the summation of

How to get average from given values

允我心安 提交于 2019-12-31 05:12:17
问题 How do I average?. I am suppose to find the average of the GPA , total of students, and the total of GPA . example: input : 4 4 4 4 output: Total Students :4 Total GPA :16 Average GPA: 4 import java.util.Scanner; public class practice { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int count = 0; double GPA = 0, total = 0, average; System.out.println("Enter GPA"); while (GPA >= 0) { GPA = keyboard.nextDouble(); total = total + GPA; count++; } average =

Average of multiple files without considering missing values

狂风中的少年 提交于 2019-12-31 03:55:09
问题 I want to calculate the average of 15 files:- ifile1.txt, ifile2.txt, ....., ifile15.txt. Number of columns and rows of each file are same. But some of them are missing values. Part of the data looks as ifile1.txt ifile2.txt ifile3.txt 3 ? ? ? . 1 2 1 3 . 4 ? ? ? . 1 ? ? ? . 1 ? ? ? . 5 ? ? ? . 4 6 5 2 . 2 5 5 1 . 3 4 3 1 . 5 5 7 1 . 0 0 1 1 . 4 3 4 0 . . . . . . . . . . . . . . . . I would like to find a new file which will show the average of these 15 fils without considering the missing