mean

Calculate mean value of two objects

我是研究僧i 提交于 2019-12-04 05:51:42
问题 Let's say we have two objects at the beginning: a <- c(2,4,6) b <- 8 If we apply the mean() function in each of them we get this: > mean(a) [1] 4 > mean(b) [1] 8 ... which is absolutely normal. If I create a new object merging a and b... c <- c(2,4,6,8) and calculate its mean... > mean(c) [1] 5 ... we get 5, which is the expected value. However, I would like to calculate the mean value of both objects at the same time. I tried this way: > mean(a,b) [1] 4 As we can see, its value differs from

Wrong result from mean(x, na.rm = TRUE)

霸气de小男生 提交于 2019-12-04 04:44:17
问题 I want to compute the mean, min and max of a series of Managers returns, as follows: ManagerRet <-data.frame(diff(Managerprices)/lag(Managerprices,k=-1)) I then replace return = 0 with NaN since data are extracted from a database and not all the dates are populated. ManagerRet = replace(ManagerRet,ManagerRet==0,NaN) I have the following 3 function > min(ManagerRet,na.rm = TRUE) [1] -0.0091716 > max(ManagerRet,na.rm = TRUE) [1] 0.007565 > mean(ManagerRet,na.rm = TRUE)*252 [1] NaN Why the mean

Numpy Mean Structured Array

£可爱£侵袭症+ 提交于 2019-12-04 03:36:22
问题 Suppose that I have a structured array of students (strings) and test scores (ints), where each entry is the score that a specific student received on a specific test. Each student has multiple entries in this array, naturally. Example import numpy grades = numpy.array([('Mary', 96), ('John', 94), ('Mary', 88), ('Edgar', 89), ('John', 84)], dtype=[('student', 'a50'), ('score', 'i')]) print grades #[('Mary', 96) ('John', 94) ('Mary', 88) ('Edgar', 89) ('John', 84)] How do I easily compute the

TensorFlow中random_normal和truncated_normal的区别

浪尽此生 提交于 2019-12-04 03:27:36
原文链接: https://blog.csdn.net/zhangdongren/article/details/83344048 区别如下: tf.random_normal(shape,mean=0.0,stddev=1.0,dtype=tf.float32,seed=None,name=None) 正太分布随机数,均值mean,标准差stddev tf.truncated_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None) 截断正态分布随机数,均值mean,标准差stddev,不过只保留[mean-2stddev,mean+2stddev]范围内的随机数 那么什么是正太分布呢? 看下面这张图,就是正太分布的直观图: 好了看完上面这张图,我们就可以理解什么是random_normal,什么又是truncated_normal了。所谓的random_normal服从正太分布的所有随机数,而truncated_normal仅仅只是截取了正太分布某一个范围的数据并不是全部数据。 ////////////////////////////////////////////////////结束线//////////////////////////////////////////////////

Datetime objects with pandas mean function

一个人想着一个人 提交于 2019-12-04 00:52:24
问题 I am new to programming so I apologize in advance if this question does not make any sens. I noticed that when I try to calculate the mean value of a pandas data frame with a date time object formatted like this: datetime.datetime(2014, 7, 10), it can not calculate the mean value of it however it seems to be able to calculate the minimum and maximum value of that same data frame with out a problem. d={'one' : Series([1, 2, 3], index=['a', 'b', 'c']), 'two' :Series([datetime.datetime(2014, 7,

What does the 11 mean in INT(11)?

时光总嘲笑我的痴心妄想 提交于 2019-12-03 20:17:34
What does the 11 mean in INT(11)? By Jeremy Smyth-Oracle on Mar 26, 2014 If you create a table using a numeric type like INT or BIGINT , you might have been surprised by the numbers that appear in the table's DESCRIBE : mysql> CREATE TABLE test(a INT, b SMALLINT, c BIGINT); Query OK, 0 rows affected (1.04 sec) mysql> DESCRIBE test; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | a | int(11) | YES | | NULL | | | b | smallint(6) | YES | | NULL | | | c | bigint(20) | YES | | NULL | | +-

Function that converts a vector of numbers to a vector of standard units

谁说胖子不能爱 提交于 2019-12-03 19:13:03
问题 Is there a function that given a vector of numbers, returns another vector with the standard units corresponding to each value? where standard unit: how many SDs a value is + or - from the mean Example: x <- c(1,3,4,5,7) # note: mean = 4, sd = 2 foo(x) [1] -1.5 -0.5 0.0 0.5 1.5 Is this fictitious "foo" function already included in a package? 回答1: yes, scale() : x <- c(1,3,4,5,7) scale(x) 回答2: The function you are looking for is scale . scale(x) [,1] [1,] -1.3416408 [2,] -0.4472136 [3,] 0

Row operations in data.table

假装没事ソ 提交于 2019-12-03 15:54:37
Im trying to perform a simple sum and mean by rows using data.table , but I am getting unexpected results. I followed the help in section 2 of the FAQ manual for data.table. I found a way that works, but I am not sure why this method in section 2 of the FAQ is not. This method gives me the incorrect result (i.e., it is giving me the value of the first column): dt[, genesum:=lapply(.SD,sum), by=gene] head(dt) gene TCGA_04_1348 TCGA_04_1362 genesum 1: A1BG 0.94565 0.70585 0.94565 2: A1BG-AS 0.97610 1.15850 0.97610 3: A1CF 0.00000 0.02105 0.00000 4: A2BP1 0.00300 0.04150 0.00300 5: A2LD1 4.57975

grouping objects to achieve a similar mean property for all groups

若如初见. 提交于 2019-12-03 13:36:46
问题 I have a collection of objects, each of which has a numerical 'weight'. I would like to create groups of these objects such that each group has approximately the same arithmetic mean of object weights. The groups won't necessarily have the same number of members, but the size of groups will be within one of each other. In terms of numbers, there will be between 50 and 100 objects and the maximum group size will be about 5. Is this a well-known type of problem? It seems a bit like a knapsack

“average length of the sequences in a fasta file”: Can you improve this Erlang code?

旧时模样 提交于 2019-12-03 13:27:50
问题 I'm trying to get the mean length of fasta sequences using Erlang . A fasta file looks like this >title1 ATGACTAGCTAGCAGCGATCGACCGTCGTACGC ATCGATCGCATCGATGCTACGATCGATCATATA ATGACTAGCTAGCAGCGATCGACCGTCGTACGC ATCGATCGCATCGATGCTACGATCTCGTACGC >title2 ATCGATCGCATCGATGCTACGATCTCGTACGC ATGACTAGCTAGCAGCGATCGACCGTCGTACGC ATCGATCGCATCGATGCTACGATCGATCATATA ATGACTAGCTAGCAGCGATCGACCGTCGTACGC >title3 ATCGATCGCATCGAT(...) I tried to answser this question using the following Erlang code: -module(golf).