VBA creation of a Matrix and double loop

I have a lot of Excel files in one folder and for each one I have (H:H) which contains a certain hour from 00:00 to 23:59 (appears within H at the format 0000 or 2359 etc ..) . Then, at a certain hour we associate a certain number of operation (conta...
more »

2017-09-11 20:09 (0) Answers

Iterate over list of NumPy matrices

I've got a list with row matrices: rows = [ matrix([[1, 0, 0]]), matrix([[0, 1, 0]]), matrix([[0, 0, 1]]) ] and I attempted to loop over these using for (a, b, c) in rows:, but instead of this working, I got an error: ValueError: not enough valu...
more »

2017-09-07 22:09 (3) Answers

caching the matrix value in R Permanently

I am working on caching a matrix and its inverse in R, I tried working on with the R.cache package but that doesn't give the result expected. I have included my code and the actual output that I am getting and also included the output that I expect p...
more »

2017-09-07 04:09 (0) Answers

Replace matrix values for each array element

I have a 3-dimensional array arr where each array element is a matrix with the same number of rows and columns. Then I have a 3-column matrix m where the first two columns specify an index (row and column) and the last column a value. arr = array(0...
more »

2017-09-06 16:09 (1) Answers

How to append group row into dataframe

I have this df1: A B C 1 2 3 5 7 9 where A B C are columns names. I have another df2 with one column: A 1 2 3 4 I would like to append df2 for each column of df1, creating this final dataframe: A B C 1 2 3 5 7 9 1 1 1 2 2 2 3 3 3 4 4 4 is ...
more »

2017-09-04 22:09 (8) Answers

How do I merge a list and a csr matrix

I have a list of numbers and its len(lex) = 6064 that looks like this [0, 0, 1, 0, 0, -1, 1, 1, 0, 0, 0, 0, 1, 0,] and a csr matrix tweets.shape = (6064, 2500) How do I merge them I tried converting them to two lists both, but whe...
more »

2017-09-04 20:09 (1) Answers

Transform Pandas Dataframe to RCV

I have a dataframe that represents a covariance matrix s.th. like this names = ['AA','BB','CC','DD','EE'] x_ = np.random.normal(size=5) y_ = np.random.normal(size=5) z = np.vstack((x_, y_)) cov_mat = np.cov(z.T) cov_mat = np.triu(cov_mat, k=0) cov_...
more »

2017-09-04 16:09 (1) Answers

Extracting chunks from a matrix by columns

Say I have a matrix with 1000 columns. I want to create a new matrix with every other n columns from the original matrix, starting from column i. So let say that n=3 and i=5, then the columns I need from the old matrix are 5,6,7,11,12,13,17,18,19 an...
more »

2017-09-03 12:09 (4) Answers

Fast subsetting of a matrix in R

I face the following problem: I need many subsets of a big matrix. Actually I just need views as input for another function f(), so I don't need to change the values. However it seems, that R is terribly slow for this task, or I'm doing something wr...
more »

2017-09-02 18:09 (2) Answers

Can't save a numpy 2-d array into a file

I have the following 2-d numpy matrix, which was a concatenation of two matrices: >>> mnist1_train_final_data=np.hstack((y_train_mnist_ni,features_train_mnist1)) >>> type(mnist1_train_final_data) <type 'numpy.ndar...
more »

2017-08-28 03:08 (1) Answers

Make numpy matrix more sparse

Suppose I have a numpy array np.array([ [3, 0, 5, 3, 0, 1], [0, 1, 2, 1, 5, 2], [4, 3, 5, 3, 1, 4], [2, 5, 2, 5, 3, 1], [0, 1, 2, 1, 5, 2], ]) Now, I want to randomly replace some elements with 0. So that I have an output like ...
more »

2017-08-26 21:08 (2) Answers

Lists and matrix using sapply

I have a perhaps basic questions and I have searched on the web. I have a problem reading files. Though, I managed to get to read my files, following @Konrad suggestions, which I appreciate: How to get R to read in files from multiple subdirectories ...
more »

2017-08-25 22:08 (2) Answers

Correlations for pairs of combinations

I have 22 variables, and I'd like to get the correlation scores, not as a matrix of correlation, but in a data frame, by pairs... I mean... Not like this v1 v2 v3 v4 v1 1 x x x v2 x 1 x x v3 x x 1 x v4 x x x 1 b...
more »

2017-08-22 21:08 (3) Answers