Multiple matrix multiplication

In numpy, I have an array of N 3x3 matrices. This would be an example of how I'm storing them (I'm abstracting away the contents): N = 10 matrices = np.ones((N, 3, 3)) I also have an array of 3-vectors, this would be an example: vectors = np.ones...
more »

2017-01-10 23:01 (1) Answers

How to select unique columns in an R matrix

I want to select the unique columns in the matrix six on a simulation as follows: > set.seed(3) > sam = replicate(100, sample(1:3, 4, rep = T)) > (six = sam[,colSums(sam)==6]) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] ...
more »

2017-01-09 04:01 (2) Answers

numpy: Compressing block matrix

Consider a matrix M1 giving values for all combinations x,y. Consider a partition f(x)->X and a partition g(y)->Y. Furthermore consider an operation p(A) on a set A of numbers, i.e. max(A) or sum(A). The mappings f,g can be used to create from...
more »

2017-01-05 16:01 (2) Answers

Combine two numpy matrixes

I have two numpy matrixes: name dimensions title (284,855) para (284, 4930) The title array contains the title of a page and the para contains the content where the first element of the title array is the title for the first element of the...
more »

2017-01-02 16:01 (1) Answers

How to split program into files- class c++

Guys I'm bit confused now, I'm trying to split program into file.h file.cpp and main.cpp, here's example of my code: //file.h// class matrix { private: class rcmatrix; rcmatrix *data; public: class Cref; class Size_Chec...
more »

2017-01-01 22:01 (1) Answers

R sum rows of matrix by column name

This seems like it should be easy but I can't figure it out. I would like to sum all of the columns of my matrix that have the same name. So, in the example below, I would like to end up with another matrix with only three columns. set.seed(4) z&l...
more »

2016-12-28 00:12 (4) Answers

saving numpy matrix in text file with indices

I am trying to save a 2D matrix A to text file for each non-zero entry. I would like to save it in the below format, For the (i,j)-th entry, one line as row[i]::column[j]::A[i,j] where row and column are 1D numpy array corresponding to rows an...
more »

2016-12-27 23:12 (2) Answers

Pandas: joining items with same index

I have a pandas data frame that is a vector with a value and an index, say: row1 10 row1 11 row2 9 row2 8 However, I want to create a 2x2 matrix from this, in which the row index is actually a header (column index). Like this: row1 row2 10 ...
more »

2016-12-22 00:12 (4) Answers

Matrix multiplication speed issues

I am investigating how cache misses influence speed of computation. I know there are many algorithms better for multiplying two matrices (even simple exchange of two of the loops below would help), but please consider this code: float a[N][N]; float...
more »

2016-12-20 20:12 (0) Answers

numpy submatrix 3D using a single indexing item

I have a 3D numpy array: K = (np.arange(36)).reshape((4,3,3))+1 [[[ 1 2 3] [ 4 5 6] [ 7 8 9]] [[10 11 12] [13 14 15] [16 17 18]] [[19 20 21] [22 23 24] [25 26 27]] [[28 29 30] [31 32 33] [34 35 36]]] where each item in K is a matrix. Now,...
more »

2016-12-15 04:12 (1) Answers

trouble with basic numpy multiplication

In my code, I multiply two matrices: c = b*a Where a outputs as array([array([-0.08358731, 0.07145386, 0.1052811 , -0.05362566]), array([-0.05335939, -0.03136824, -0.01260714, 0.11532605]), array([-0.09164538, 0.02280118, -0.00...
more »

2016-12-12 18:12 (2) Answers

String to np.matrix back to string

I read a string data from a TCP port and it looks like this: data_string = '1,1.0,2.4,4,3,0.0,0.0,0.0,7,-2.5,80,1481307702.180;2,3.3,10.1,2,2,0.0,-0.0625,-0.25,7,-20.0,3,1481307702.180;3,-0.2,1.5,4,4,0.0,0.0,0.0,7,-7.0,80,1481307702.180;4,-3.7,25.4,...
more »

2016-12-12 17:12 (1) Answers

Divide and Conquer In-place Transpose of a Matrix

I'm working on an implementation of the approach described in the wiki article for the in-place cache-oblivious transposition of a square Matrix. https://en.wikipedia.org/wiki/In-place_matrix_transposition The algorithm basically recursively split...
more »

2016-12-08 15:12 (1) Answers