matrix

MATLAB: detect and remove mirror imaged pairs in 2 column matrix

风格不统一 提交于 2020-01-13 09:25:09
问题 I have a matrix [1 2 3 6 7 1 2 1] and would like to remove mirror imaged pairs..i.e. output would be either: [1 2 3 6 7 1] or [3 6 7 1 2 1] Is there a simple way to do this? I can imagine a complicated for loop, something like (or a version which wouldn't delete the original pair..only the duplicates): for i=1:y var1=(i,1); var2=(i,2); for i=1:y if array(i,1)==var1 && array(i,2)==var2 | array(i,1)==var2 && array(i,2)==var1 array(i,1:2)=[]; end end end thanks 回答1: How's this for simplicity - A

Traversing a boost::ublas matrix using iterators

廉价感情. 提交于 2020-01-13 09:17:05
问题 I simply want to traverse a matrix from start to finish touching upon every element. However, I see that there is no one iterator for boost matrix, rather there are two iterators, and I haven't been able to figure out how to make them work so that you can traverse the entire matrix typedef boost::numeric::ublas::matrix<float> matrix; matrix m1(3, 7); for (auto i = 0; i < m1.size1(); i++) { for (auto j = 0; j < m1.size2(); j++) { m1(i, j) = i + 1 + 0.1*j; } } for (auto itr1 = m1.begin1(); itr1

Computing the null space of a bigmatrix in R

会有一股神秘感。 提交于 2020-01-13 07:48:07
问题 I can not find any function or package to calculate the null space or (QR decomposition) of a bigmatrix (from library(bigmemory) ) in R. For example: library(bigmemory) a <- big.matrix(1000000, 1000, type='double', init=0) I tried the following but got the errors shown. How can I find the null space of a bigmemory object? a.qr <- Matrix::qr(a) # Error in as.vector(data) : # no method for coercing this S4 class to a vector q.null <- MASS::Null(a) # Error in as.vector(data) : # no method for

R - I want to go through rows of a big matrix and remove all zeros

流过昼夜 提交于 2020-01-13 06:48:29
问题 I have a lot of rows and columns in a very large matrix (184 x 4000, type double), and I want to remove all 0's. The values in the matrix are usually greater than 0 but there are some rows of 0.0000 . I tried to remove the rows with zeros using this: x <- x[which(rowSums(x) > 0),] but what I am left with is a mere 3 rows out of 184. And I know for a fact that the deleted 181 rows were not all 0 rows. Does anyone have a clue why this is happening and how I can fix it? I used this same code on

Column referencing: [[i]] vs [,i] for matrix, dataframe, and data.table

倾然丶 夕夏残阳落幕 提交于 2020-01-13 06:32:00
问题 Could someone please explain to me the difference in column referencing between matrix , data.frame , and data.table ? I'm getting my head around which syntax to use for each class, but I don't understand how/why they're different. Take a 10x10 matrix foo <- matrix( nrow = 10, ncol = 10 ) I'll just fill the 2nd column to demonstrate: foo[,2] <- rnorm(10) head( foo, 3 ) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] NA -0.4688874 NA NA NA NA NA NA NA NA [2,] NA -1.0273370 NA NA NA NA

How to pixelate a set of lines into a matrix

此生再无相见时 提交于 2020-01-13 06:15:10
问题 It looks a very simple question. There are many lines available as their two endpoints. The question is how to discretize them into a matrix . Then the matrix can be used for image processing purposes. At the following figure example lines (yellow) and their corresponding pixelated demonstrations are shown. A piece of code in any language would be of great help and strongly recommended and of course is in advance appreciated. Note that performance and accuracy are very important factors. Also

How to duplicate elements of a matrix without using the repmat function

一个人想着一个人 提交于 2020-01-13 06:06:07
问题 Given the matrix I = [1,2;3,4] , I would like to duplicate the elements to create a matrix I2 such that: I2 = [1 1 1 2 2 2 1 1 1 2 2 2 1 1 1 2 2 2 3 3 3 4 4 4 3 3 3 4 4 4 3 3 3 4 4 4] Other than using repmat , what other methods or functions are available? 回答1: Use kron: >> N = 3 %// Number of times to replicate a number in each dimension >> I = [1,2;3,4]; >> kron(I, ones(N)) ans = 1 1 1 2 2 2 1 1 1 2 2 2 1 1 1 2 2 2 3 3 3 4 4 4 3 3 3 4 4 4 3 3 3 4 4 4 This probably deserves some explanation

R multiple conditions in row selection of matrix [duplicate]

此生再无相见时 提交于 2020-01-13 05:39:07
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: R: subset() logical-and operator for combining conditions should be & not && I have a simple question, but I don't know how to solve this... I want to select all rows where value_1 > 0 and value_2 > 0. Now I have this code: dataOnBoth<-data[data$value_1 > 0,][data$value_2 > 0,] When I head this data, ordering on log2_fold_change, I have This output: gene_id sample_1 sample_2 status value_1 value_2 log2_fold

Is it possible to save only half of a symmetric matrix to save the memory?

穿精又带淫゛_ 提交于 2020-01-13 03:08:14
问题 There is a large matrix that is used in Ax=b type problem. A is symmetric. Is there any algorithm to let us save only half of the matrix and do operation like x=A\b on it? 回答1: You'll only save half the memory, but you can do this by creating a flat version of the matrix, saving that, then unflattening it. The extra time required probably doesn't make the saving worthwhile, mind: % pretend this is symettric... A = rand(10, 10); % store it as a flat list flatA = []; for k = 1:size(A,1) flatA =

Can an R matrix contain different datatypes? Does this hacked-up matrix-of-lists work?

微笑、不失礼 提交于 2020-01-13 02:29:48
问题 I read these: https://stackoverflow.com/a/5159049/1175496 Matrices are for data of the same type. https://stackoverflow.com/q/29732279/1175496 Vectors (and so matrix) can accept only one type of data If matrix can only accept one data type, why can I do this: > m_list<-matrix(list('1',2,3,4),2,2) > m_list [,1] [,2] [1,] "1" 3 [2,] 2 4 The console output looks like I am combining character and integer data types. The console output looks similar to this matrix: > m_vector<-matrix(1:4,2,2) > m