mean

Why skimage mean filter does not work on float array?

送分小仙女□ 提交于 2019-12-11 04:24:57
问题 I am going to apply a mean filter on an array of float with window_size=3 for example. I have found this library: from skimage.filters.rank import mean import numpy as np x=np.array([[1,8,10], [5,2,9], [7,2,9], [4,7,10], [6,14,10]]) print(x) print(mean(x, square(3))) [[ 1 8 10] [ 5 2 9] [ 7 2 9] [ 4 7 10] [ 6 14 10]] [[ 4 5 7] [ 4 5 6] [ 4 6 6] [ 6 7 8] [ 7 8 10]] but this function can't run on float arrays: from skimage.filters.rank import mean import numpy as np x=np.array([[1,8,10], [5,2,9

Compute sample statistics for a data vector with ties which is stored as a frequency table

妖精的绣舞 提交于 2019-12-11 04:21:21
问题 I am trying to get some summary statistics (mean, variance and quantiles) from a data vector with tied values. In particular, it is stored in a frequency distribution table: unique data values var and number of ties frequency . I know I could use rep function to first expand the vector to its full format: xx <- rep(mydata$var, mydata$frequency) then do standard mean(xx) var(xx) quantile(xx) But the frequency is really large and I have many unique values, which makes the program really slow.

why dim of colMeans/rowMeans return null?

感情迁移 提交于 2019-12-11 03:33:21
问题 I am new to R. I have the following code sigma1 = matrix(c(2,0,0,1),2,2) mu1 = matrix(c(0,10),2,1) x1 = t(mvrnorm(n = 5, mu1, sigma1)) print(rowMeans(x1)) print(dim(colMeans(x1))) and for some reason I get NULL for dimension of row/col means. 回答1: 'as.matrix' turns the vector 'colMeans(x1)' into a matrix. Then the dimensions are 5 and 1, as expected: library(rockchalk) sigma1 = matrix(c(2,0,0,1),2,2) mu1 = matrix(c(0,10),2,1) x1 = t(mvrnorm(n = 5, mu1, sigma1)) print(rowMeans(x1)) print(dim

Finding the mean of the log-normal distribution in survival analysis in R

不问归期 提交于 2019-12-11 03:24:49
问题 I am a novice with R. Currently I am fitting a log-normal distribution to some survival data I have, however I have become stuck when trying to calculate statistics such as the median and the mean. This is the code I have used so far, can anyone tell me what I should type next to find the mean? # rm(list=ls(all=TRUE)) library(survival) data<-read.table("M:\\w2k\\Diss\\Hoyle And Henley True IPD with number at risk known.txt",header=T) attach(data) data times_start <-c( rep(start_time_censor, n

Computing mean of all tuple values where 1st number is similar

北城以北 提交于 2019-12-11 02:29:08
问题 Consider list of tuples [(7751, 0.9407466053962708), (6631, 0.03942129), (7751, 0.1235432)] how to compute mean of all tuple values in pythonic way where 1st number is similar? for example the answer has to be [(7751, 0.532144902698135), (6631, 0.03942129)] 回答1: One way is using collections.defaultdict from collections import defaultdict lst = [(7751, 0.9407466053962708), (6631, 0.03942129), (7751, 0.1235432)] d_dict = defaultdict(list) for k,v in lst: d_dict[k].append(v) [(k,sum(v)/len(v))

How to get a mean array with numpy

ⅰ亾dé卋堺 提交于 2019-12-11 02:03:20
问题 I have a 4-D(d0,d1,d2,d3,d4) numpy array. I want to get a 2-D(d0,d1)mean array, Now my solution is as following: area=d3*d4 mean = numpy.sum(numpy.sum(data, axis=3), axis=2) / area But How can I use numpy.mean to get the mean array. 回答1: You can reshape and then perform the average: res = data.reshape(data.shape[0], data.shape[1], -1).mean(axis=2) In NumPy 1.7.1 you can pass a tuple to the axis argument: res = np.mean(data, axis=(2,3,4)) 回答2: In at least version 1.7.1, mean supports a tuple

Mean of columns with same label

断了今生、忘了曾经 提交于 2019-12-11 01:53:58
问题 I have two vectors data vector: A = [1 2 2 1 2 6; 2 3 2 3 3 5] label vector: B = [1 2 1 2 3 NaN] I want to take the mean of all columns that have the same label and output these as a matrix sorted by label number, ignoring NaNs. So, in this example I would want: labelmean(A,B) = [1.5 1.5 2; 2 3 3] This can be done with a for-loop like this. function out = labelmean(data,label) out=[]; for i=unique(label) if isnan(i); continue; end out = [out, mean(data(:,label==i),2)]; end However, I'm

calculate a mean by criteria in R

家住魔仙堡 提交于 2019-12-11 01:29:23
问题 I would like to calculate a sample mean in R by introducing a specific criteria. For example I have this table and I want the means of only those for whom stage = 1 or 2: treatment session period stage wage_accepted type 1 1 1 1 25 low 1 1 1 3 19 low 1 1 1 3 15 low 1 1 1 2 32 high 1 1 1 2 13 low 1 1 1 2 14 low 1 1 2 1 17 low 1 1 2 4 16 low 1 1 2 5 21 low The desired out in this case should be: stage mean 1 21.0 2 19.6667 Thanks in advance. 回答1: With the dplyr library library(dplyr) df %>%

Mocha test failing to run on nodejs server [duplicate]

佐手、 提交于 2019-12-11 00:09:32
问题 This question already has answers here : npm error ELIFECYCLE while running the test (4 answers) Closed 3 years ago . Objective Find out why my tests crash when I fail the assert. Background I have a very simple NodeJs application, and I am using Mocha for BDD with no assertion framework (just the basic assert from NodeJs). I run my Mocha test using npm test and I have the following package.json file: { "name": "server", "version": "1.0.0", "description": "Mah Project!", "main": "index.js",

pandas groupby mean with nan

不羁岁月 提交于 2019-12-10 22:08:30
问题 I have the following dataframe: date id cars 2012 1 4 2013 1 6 2014 1 NaN 2012 2 10 2013 2 20 2014 2 NaN Now, I want to get the mean of cars over the years for each id ignoring the NaN's. The result should be like this: date id cars result 2012 1 4 5 2013 1 6 5 2014 1 NaN 5 2012 2 10 15 2013 2 20 15 2014 2 NaN 15 I have the following command: df["result"]=df.groupby("id")["cars"].mean() The command runs without errors, but the result column only has NaN's. What did I do wrong? 回答1: Use