matrix

Efficiently finding non zero numbers from a large matrix

前提是你 提交于 2021-01-29 02:18:23
问题 I have a 512 x 512 x 112 matrix with three kind of values : zeroes, non zeroes and NaN. How can I get the indices of the non zero values of the matrix efficiently (without using loop)? 回答1: The comment from @scmg is the way to go- Matlab's linear logical indexing is a way to avoid looping over the elements; it only takes 1.2 sec on my PC. Here is a working example: rng(8675309) %jenny number for consistency x=randn([512,512,112]); % make random matrix x(x<0)=NaN; % set some elements to NaN x

Efficiently finding non zero numbers from a large matrix

十年热恋 提交于 2021-01-29 02:17:19
问题 I have a 512 x 512 x 112 matrix with three kind of values : zeroes, non zeroes and NaN. How can I get the indices of the non zero values of the matrix efficiently (without using loop)? 回答1: The comment from @scmg is the way to go- Matlab's linear logical indexing is a way to avoid looping over the elements; it only takes 1.2 sec on my PC. Here is a working example: rng(8675309) %jenny number for consistency x=randn([512,512,112]); % make random matrix x(x<0)=NaN; % set some elements to NaN x

How to dynamically list matrices as elements in a list in R [duplicate]

醉酒当歌 提交于 2021-01-28 19:53:19
问题 This question already has answers here : Make a list of many objects from a vector of object names [duplicate] (2 answers) Closed 6 months ago . This post is similar to my other post Let's say if I have 4 matrices: x1 <- matrix(1:9, nrow = 3) x2 <- matrix(2:10, nrow = 3) x3 <- matrix(3:11, nrow = 3) x4 <- matrix(4:12, nrow = 3) And I want to put them into a list() in a way like this: [[1]] [[1]][[1]] [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 [[1]][[2]] [,1] [,2] [,3] [1,] 2 5 8 [2,] 3 6

Python: how to transpose part of matrix

霸气de小男生 提交于 2021-01-28 12:11:08
问题 If I have a matrix like this: matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] how can I get this: matrix = [[1, 2, 3, 4], [5, 6, 10, 14], [9, 7, 11, 15], [13, 8, 12, 16]] That is, how can I exclude the first row and the first column and transpose the rest? I tried this, it leaves the matrix unchanged: for i in range(1, 4): for j in range(1, 4): temp = copy.deepcopy(matrix[i][j]) matrix[i][j] = matrix[j][i] matrix[j][i] = temp And when I try: new_matrix = list(matrix)

SVG - How to apply a gradient transform matrix to a linear gradient brush?

独自空忆成欢 提交于 2021-01-28 12:09:11
问题 I'm writing a SVG viewer application in c++ language. I actually face a transform issue in several SVG files that I cannot figure out. Considering the following SVG file: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- Created with Inkscape (http://www.inkscape.org/) --> <svg id="svg9686" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="90mm" width="145mm" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:xlink="http:/

How to unfold a Matrix on Matlab?

≡放荡痞女 提交于 2021-01-28 11:31:15
问题 I have a given matrix H and I would like to unfold (expand) it to find a matrix B by following the method below : Let H be a matrix of dimension m × n . Let x = gcd (m,n) The matrix H is cut in two parts. The cutting pattern being such that : The "diagonal cut" is made by alternately moving c = n/x units to the right (we move c units to the right several times). We alternately move c-b = m/x units down (i.e. b = (n-m)/x ) (we move b units down several times). After applying this "diagonal cut

Finding all solutions of a non-square linear system with infinitely many solutions

让人想犯罪 __ 提交于 2021-01-28 09:25:58
问题 In this question was found a solution to find a particular solution to a non-square linear system that has infinitely many solutions. This leads to another question: How to find all the solutions for a non-square linear system with infinitely many solutions, with R? (see below for a possible description of the infinite set of solutions) Example: the linear system x+y+z=1 x-y-2z=2 is equivalent to A X = B with: A=matrix(c(1,1,1,1,-1,-2),2,3,T) B=matrix(c(1,2),2,1,T) A [,1] [,2] [,3] [1,] 1 1 1

Finding all solutions of a non-square linear system with infinitely many solutions

让人想犯罪 __ 提交于 2021-01-28 09:25:24
问题 In this question was found a solution to find a particular solution to a non-square linear system that has infinitely many solutions. This leads to another question: How to find all the solutions for a non-square linear system with infinitely many solutions, with R? (see below for a possible description of the infinite set of solutions) Example: the linear system x+y+z=1 x-y-2z=2 is equivalent to A X = B with: A=matrix(c(1,1,1,1,-1,-2),2,3,T) B=matrix(c(1,2),2,1,T) A [,1] [,2] [,3] [1,] 1 1 1

Eigen Indices of Dense Matrix meeting Condition

老子叫甜甜 提交于 2021-01-28 08:03:24
问题 I'm looking to get the row/column indices from a dense matrix which meet a condition. In my case the result is likely to be very sparse. For example, with matrix 1 5 2 7 6 3 2 3 8 I'd like to get the indicies where the coeff is greater than 4, or (0,1), (1,0), (1,1), (2,2) My initial thoughts include using either select or coefficientwise operations to build a bool/int matrix 0 1 0 1 1 0 0 0 1 and then convert it to a sparse matrix (0,1,1), (1,0,1), (1,1,1), (2,2,1) then remove the coeff

Eigen: convert rotation matrix to quaternion then back getting completely different matrices

雨燕双飞 提交于 2021-01-28 07:27:26
问题 Can anyone help me out with Eigen? I tried to convert quaternion to matrix and then back and got completely different matrices. I am not able to trust quaternion before understanding this issue. Here is the code: #include <Eigen/Geometry> #include <iostream> void Print_Quaternion(Eigen::Quaterniond &q){ std::cout<<"["<<q.w()<<" "<<q.x()<<" "<<q.y()<<" "<<q.z()<<"]"<<std::endl; } void Verify_Orthogonal_Matrix(Eigen::Matrix3d &m) { std::cout<<"|c0|="<<m.col(0).norm()<<",|c1|="<<m.col(1).norm()<