Write a for loop in a function to get a matrix

I need to put delta.vec and sigma.vec values through my required.replicates function and store them in my practice1 matrix. But I get NULL. sigma.vec <- c(2,4,6,8,10,12) delta.vec <- c(1,2,5,8,10) practice1 <- matrix(0, nrow=length(delta...
more »

2017-06-17 14:06 (1) Answers

Dealing With Matrices in Python

I am new to python and facing a problem in dealing with Matrices. I have a matrix, let's say A = [1 0 0 2; 3 3 3 2; 3 3 0 2; 3 4 4 4] Now, I want to make all the elements in the matrix equal to zero, except elements which are repeated the maximum...
more »

2017-06-12 08:06 (4) Answers

For loop number path calculation

I have a bidirectional network, that is, a network where flow exists both from i->j and j->i. And I want to calculate the number of simple paths between each [i,j] and report in matrices according to the path length, that is, for each [i,j] pair ther...
more »

2017-05-19 16:05 (0) Answers

Multiplying by pattern matching

I have a matrix of the following format: matrix = np.array([1, 2, 3, np.nan], [1, np.nan, 3, 4], [np.nan, 2, 3, np.nan]) and coefficients I want to selectively multiply element-wise with my matrix: coefficient...
more »

2017-05-11 18:05 (1) Answers

Slow dot product in R

I am trying to take the dot product from a 331x23152 and 23152x23152 matrix. In Python and Octave this is a trivial operation, but in R this seems to be incredibly slow. N <- 331 M <- 23152 mat_1 = matrix( rnorm(N*M,mean=0,sd=1), N, M) mat_...
more »

2017-05-08 18:05 (3) Answers

summation of sub-matrices of boolean numpy arrays

I have a 11x51 boolean matrix a. On this I do this operation in Matlab to obtain a boolean matrix of size 10x50. a = logical(a(1:end-1,1:end-1) + a(2:end,1:end-1) + a(1:end-1,2:end) + a(2:end,2:end)) I want to do this in python. I tried this:- a ...
more »

2017-05-07 22:05 (2) Answers

Double loop to fill a correlation matrix

I have a dataset like this set.seed(1) a = abs(rnorm(10, mean = 0, sd= 1)) b = abs(rnorm(10, mean = 0, sd= 1)) c = abs(rnorm(10, mean = 0, sd= 1)) d = abs(rnorm(10, mean = 0, sd= 1)) df = as.data.frame(cbind(a, b, c, d)) And i want to get a table ...
more »

2017-05-03 20:05 (2) Answers

Sum nth columns elementwise in Numpy matrix

I have the following numpy matrix: A = [[a,b,c,d,e,f], [g,h,i,j,k,l], ...] I need to sum all the nth columns in a element-wise fashion. So, if n is 2, the answer needs to be: B = [[a+c+e, b+d+f], [g+i+k, h+j+l], ...] (like...
more »

2017-05-02 18:05 (1) Answers