Questions tagged [matrix]

In mathematics, a matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. The individual items in a matrix are called its elements or entries.

In mathematics, a matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. The individual items in a matrix are called its elements or entries.

Matrices with the same number of rows and columns can be added or subtracted element by element. But the rule for matrix multiplication is that two matrices can be multiplied only when the number of columns in the first equals the number of rows in the second.

Types of matrices

A matrix can be represented as a 2-d (two dimensional) array in any programming language, where one of the two dimensions defines row elements of a matrix, and other dimension defines column elements of the matrix.

Tag usage

The tag can contain programming related problems in implementing matrices. Questions in this tag will be related to a multidimensional array, so these questions can also be tagged with . Please avoid mathematical problems on stackoverflow (use the Mathematics Stack Exchange site instead).

Also note these related tags:

Read more

36680 questions
6
votes
1 answer

How can we change the rotation origin (pivot point) of a Three.js object without modifying scene tree structure or geometry?

I know we can make the object have a new parent to act as the pivot, or we could adjust the geometry position within the mesh. But how can we achieve this mathematically without reparenting the object or modifying the object's parent, and without…
trusktr
  • 34,715
  • 41
  • 148
  • 226
6
votes
1 answer

mapply basics? - how to create a matrix from two vectors and a function

I am trying create a data.frame from which to create a graph. I have a function and two vectors that I want to use as the two inputs. This is a bit simplified, but basically all I have is: relGPA <- seq(-1.5,1.5,.2) avgGPA <- c(-2,0,2) f <-…
Sam Swift
  • 833
  • 1
  • 11
  • 17
6
votes
5 answers

Matrix, algorithm interview question

This was one of my interview questions. We have a matrix containing integers (no range provided). The matrix is randomly populated with integers. We need to devise an algorithm which finds those rows which match exactly with a column(s). We need to…
Brahadeesh
  • 2,207
  • 8
  • 37
  • 57
6
votes
3 answers

Find out if two symmetric matrices are the same up to a permutation of the rows/columns

I have two symmetric (item co-occurrence) matrices A and B and want to find out if they describe the same co-occurrence, only with the row/column labels permuted. (The same permutation has to be applied to rows and columns to keep the…
C. Yduqoli
  • 1,160
  • 10
  • 14
6
votes
1 answer

Implementing Indexer in F#

I am trying to convert this C# code to F#: double[,] matrix; public Matrix(int rows, int cols) { this.matrix = new double[rows, cols]; } public double this[int row, int col] { get { return…
Beaker
  • 2,594
  • 5
  • 29
  • 52
6
votes
1 answer

Gaussian Elimination in Java

I was trying to implement a Matrix.class to learn some Java. Right now, I have some difficulties with a method that should return the matrix after Gaussian elimination which will be used to find the inverse of a matrix later on. Here is what I came…
anddromedar
  • 63
  • 1
  • 3
6
votes
1 answer

Why isn't column-wise operation much faster than row-wise operation (as it should be) for a matrix in R

Consider the following functions which store values row-wise-ly and column-wise-ly. #include using namespace Rcpp; const int m = 10000; const int n = 3; // [[Rcpp::export]] SEXP rowWise() { SEXP A = Rf_allocMatrix(INTSXP, m, n); …
Randy Lai
  • 2,937
  • 2
  • 18
  • 22
6
votes
3 answers

How to find the column means for a sparse matrix excluding 0 values?

I have a sparse matrix structured similar to this, but much larger. library(Matrix) dfmtest<-new("dgCMatrix" , i = c(0L, 1L, 2L, 4L, 5L, 6L, 8L, 0L, 1L, 2L, 3L, 4L, 6L, 7L, 8L, 0L, 2L, 3L, 6L, 7L, 8L, 1L, 2L, 4L, 5L, 6L, 7L, 8L, 9L, 0L, 1L,…
user2355903
  • 453
  • 1
  • 3
  • 17
6
votes
1 answer

Any idea to optimise this algorithm?

Let's imagine I have a binary 40*40 matrix. In this matrix, values can be either ones or zeros. I need to parse the whole matrix, for any value == 1, apply the following : If the following condition is met, keep the value = 1, else modify the value…
Jonathan DEKHTIAR
  • 3,024
  • 1
  • 11
  • 41
6
votes
3 answers

Sum matrix elements group by indices in Python

I have two matrix (same row and column): one with float values, which are grouped by indices in the other matrix. As a result, I want a dictionary or a list with the sums of the elements for each index. Indices always start at 0. A =…
Mortafix
  • 95
  • 8
6
votes
1 answer

Randomly sample contiguous rows from a data frame or matrix

I want to sample a number of contiguous rows from a data frame df. df <- data.frame(C1 = c(1, 2, 4, 7, 9), C2 = c(2, 4, 6, 8, 10)) I am trying to get something similar to the following which allows me to sample 3 random rows and repeat the process…
Eric González
  • 343
  • 1
  • 9
6
votes
3 answers

How to sum parts of a matrix of different sizes, without using for loops?

I have a relatively large matrix NxN (N~20,000) and a Nx1 vector identifying the indices that must be grouped together. I want to sum together parts of the matrix, which in principle can have a different number of elements and non-adjacent…
user9998992
  • 125
  • 6
6
votes
1 answer

how to save a matrix as an image in Julia in 2018

This is a trivial question, of course, but I'm having a hard time finding a working answer. Given a matrix A ( either 2d for grayscale, or 3d for RGB) how to save it on the disk as an image file using Julia? I have an old code written in 2016 when…
Hayk
  • 487
  • 2
  • 8
  • 15
6
votes
5 answers

How to calculate matrix determinant? n*n or just 5*5

everyone. I need to find matrix n*n (or 5*5) determinant. I have a function translated from Pascal, but there's INDEX OUT OF RANGE EXCEPTION. Could somebody help me? Here's my code: public static double DET(double[,] a, int n) { int i,…
Frankie Drake
  • 1,073
  • 9
  • 19
  • 37
6
votes
2 answers

How to calculate a rotation matrix in n dimensions given the point to rotate, an angle of rotation and an axis of rotation (n-2 subspace)

I would like to calculate an (nxn) rotation matrix in the n-dimensional space given the following: The point to rotate. An angle of rotation. An axis of rotation (an (n-2) subspace that passes through the origin given by (n-2) unit vectors that…
David
  • 451
  • 3
  • 11
1 2 3
99
100