matrix

Find the most repeated row in a matrix

前提是你 提交于 2020-01-11 09:11:10
问题 I have about 10000 replicates of a sample in a matrix. My matrix has 1000 rows and 6 columns. Numbers in the columns range from 0:58 depending on the sample. actual.prob <- c(.14, .14, .16, .13, .19, .24) million.rep <- replicate(10000, sample(1:6, 58, replace= T, actual.prob)) new.matrix <- matrix(nrow= 10000, ncol=6) for(i in 1:10000){ new.matrix[i,] <- as.vector(table(factor(million.rep[,i], levels=1:6))) } new.matrix[1:10,] [,1] [,2] [,3] [,4] [,5] [,6] [1,] 3 7 11 11 11 15 [2,] 7 6 12 5

canvas is offset by setting identity matrix in onDraw of custom view

人走茶凉 提交于 2020-01-11 07:18:34
问题 I set a matrix to my canvas in the onDraw method of a custom view via canvas.setMatrix(matrix); then I just draw a grid using predefined paints: canvas.drawRect(0,0,viewWidth,viewHeight, background); for(int i=0; i <= nRows; i++){ canvas.drawLine(0,i*cellHeight, nCols*cellWidth,i*cellHeight,lines); canvas.drawLine(i*cellWidth, 0, i*cellWidth, nRows*cellHeight, lines); if(i != nRows) canvas.drawText(""+i, i*cellWidth, (i+1)*cellHeight, text); } and for some reason the whole canvas is offset by

Printing the sorted elements of a matrix in descending order with array indices in the fastest fashion

安稳与你 提交于 2020-01-11 06:42:09
问题 This seems like a simple problem but I am having trouble doing this in a fast manner. Say I have a matrix and I want to sort this matrix and store the indices of the elements in descending order. Is there a quick way to do this? Right now, I am extracting the maximum, storing the result, changing it to -2, and then extracting the next maximum in a for loop. Which is probably the most inefficient way to do it. My problem actually requires me to work on a 20,000 X 20,000 matrix. Memory is not

A numpy array unexpectedly changes when changing another one despite being separate

£可爱£侵袭症+ 提交于 2020-01-11 03:22:13
问题 I found a bug in my large code, and I simplified the issue to the case below. Although in each step I only change w2 , but when at each step I print out w1 , it is also changed, because end of the first loop I assign them to be equal. I read for this but there was written in case I make w1 = w2[:] it will solve the issue but it does not import numpy as np import math w1=np.array([[1,2,3],[4,5,6],[7,8,9]]) w2=np.zeros_like(w1) print 'w1=',w1 for n in range(0,3): for i in range(0,3): for j in

Linear indexing in symmetric matrices

懵懂的女人 提交于 2020-01-11 02:05:11
问题 We can access matrices using linear indexing, which follows this pattern 0 1 2 3 4 5 6 7 8 It's easy to get the i,j coordinates for this case (n is the matrix dimension). For 0-index based, it would be. i = index / n j = index % n Now, what if my matrix is symmetric and I only want to access the upper part 0 1 2 3 .. 4 5 6 ..... 7 8 ........ 9 I know the linear index will be given by index = j + n*i - i (i-1) / 2 but I want to know i,j given idx. Do you guys know of any way of doing this?. I

Select n first rows of a matrix

风流意气都作罢 提交于 2020-01-11 01:50:07
问题 How can I select, say top 100 rows of a matrix in R? All I found is using subset which requires condition parameter. All I need to make smaller matrix by using only first n number of rows with same number of columns 回答1: Use the head function: head(mat, 100) 回答2: The simplest way to do it would be a[1:100,] (unless there are fewer than 100 rows, in which case head(a,100) works better) 来源: https://stackoverflow.com/questions/17819909/select-n-first-rows-of-a-matrix

Select n first rows of a matrix

吃可爱长大的小学妹 提交于 2020-01-11 01:50:06
问题 How can I select, say top 100 rows of a matrix in R? All I found is using subset which requires condition parameter. All I need to make smaller matrix by using only first n number of rows with same number of columns 回答1: Use the head function: head(mat, 100) 回答2: The simplest way to do it would be a[1:100,] (unless there are fewer than 100 rows, in which case head(a,100) works better) 来源: https://stackoverflow.com/questions/17819909/select-n-first-rows-of-a-matrix

Matrix/Tensor Triple Product?

拥有回忆 提交于 2020-01-11 01:41:18
问题 An algorithm I'm working on requires computing, in a couple places, a type of matrix triple product. The operation takes three square matrices with identical dimensions, and produces a 3-index tensor. Labeling the operands A , B and C , the (i,j,k) -th element of the result is X[i,j,k] = \sum_a A[i,a] B[a,j] C[k,a] In numpy, you can compute this with einsum('ia,aj,ka->ijk', A, B, C) . Questions: Does this operation have a standard name? Can I compute this with a single BLAS call? Are there

Perform pairwise comparison of matrix

南楼画角 提交于 2020-01-10 20:18:51
问题 I have a matrix of n variables and I want to make an new matrix that is a pairwise difference of each vector, but not of itself. Here is an example of the data. Transportation.services Recreational.goods.and.vehicles Recreation.services Other.services 2.958003 -0.25983789 5.526694 2.8912009 2.857370 -0.03425164 5.312857 2.9698044 2.352275 0.30536569 4.596742 2.9190123 2.093233 0.65920773 4.192716 3.2567390 1.991406 0.92246531 3.963058 3.6298314 2.065791 1.06120930 3.692287 3.4422340 I tried

OpenGL 3 (LWJGL) LookAt Matrix Confusion

拥有回忆 提交于 2020-01-10 19:40:11
问题 I'm learning OpenGL 3 using LWJGL. I have tried to implement an equivalent to gluLookAt() , and although it works am I somewhat confused as to why. I confess to just copying this code from various sources on the web, but after much study I think understand the maths behind it, and that I understand what LWJGL is doing. However the 'correct' gluLookAt code behaved incorrectly in my application, as the camera seemed to be turning the wrong way. I only managed to get my code working by