Questions tagged [submatrix]

A submatrix is a matrix formed by selecting a subset of the rows and columns of one larger matrix. Questions tagged [submatrix] deal with implementation issues regading accessing the relevant rows/columns of the larger matrix, relevant memory issues, etc.

A submatrix is a matrix formed by selecting a subset of the rows and columns of one larger matrix.

For example, let A be a matrix of size n-by-m

A = [ a00 a01 ...
      a10 a11 ...
      .       .
      .        .
      .         .
      an1 an2 ... anm ]

Then one can form a 2-by-3 sub-matrix by selecting rows 2 and 5, and columns 1,4 and 6.
The resulting sub-matrix is then

S = [ a21 a24 a26
      a51 a54 a56 ]

Questions tagged [submatrix] deal with implementation issues regading accessing the relevant rows/columns of the larger matrix, relevant memory issues, etc.

183 questions
175
votes
6 answers

Select rows of a matrix that meet a condition

In R with a matrix: one two three four [1,] 1 6 11 16 [2,] 2 7 12 17 [3,] 3 8 11 18 [4,] 4 9 11 19 [5,] 5 10 15 20 I want to extract the submatrix whose rows have column three = 11. That is: …
peter2108
  • 5,580
  • 6
  • 24
  • 18
66
votes
11 answers

Getting the submatrix with maximum sum?

Input: A 2-dimensional array NxN - Matrix - with positive and negative elements.Output: A submatrix of any size such that its summation is the maximum among all possible submatrices. Requirement: Algorithm complexity to be of O(N^3) History: With…
guirgis
  • 1,133
  • 2
  • 14
  • 17
15
votes
4 answers

Submatrices and indices using Eigen

I'm currently working on a MATLAB project and I'd like to re-implement the most computational-heavy parts using C++ and Eigen. I'd like to know if there's a way to perform the following operation (MATLAB syntax): B = A(A < 3); For those who are not…
Ilio Catallo
  • 3,152
  • 2
  • 22
  • 40
12
votes
4 answers

slicing sparse (scipy) matrix

I would appreciate any help, to understand following behavior when slicing a lil_matrix (A) from the scipy.sparse package. Actually, I would like to extract a submatrix based on an arbitrary index list for both rows and columns. When I used this two…
user972858
  • 121
  • 1
  • 1
  • 3
8
votes
3 answers

MATLAB: extract submatrix with logical indexing

I'm looking for an elegant solution to this very simple problem in MATLAB. Suppose I have a matrix >> M = magic(5) M = 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 …
foglerit
  • 7,792
  • 8
  • 44
  • 64
6
votes
1 answer

How to join matrices in Armadillo

I have several processes, each computing its own matrix. Finally, I want them to send their solved matrices to the root process, which will literally join them into one big matrix and output this simply in ASCII format into a text file. Is it…
Eenoku
  • 2,741
  • 4
  • 32
  • 64
6
votes
2 answers

find largest submatrix algorithm

I have an N*N matrix (N=2 to 10000) of numbers that may range from 0 to 1000. How can I find the largest (rectangular) submatrix that consists of the same number? Example: 1 2 3 4 5 -- -- -- -- -- 1 | 10 9 9 9 80 2 | 5 9 9 9 10 3…
user277585
  • 69
  • 1
  • 3
6
votes
1 answer

Getting all submatrices

I have got an N×M matrix m like: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 I want to get all submatrices of size P×Q (P,Q are odd) w/o employing a for-loop. The result s should be a P×Q×((N-P+1)·(M-Q+1)) matrix. E.g. if P=Q=3: s(:,:,1) = [1 2…
Kijewski
  • 25,517
  • 12
  • 101
  • 143
5
votes
3 answers

Matlab: Find the distance from an element to the matrix border

Say in Matlab I have a matrix like this: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 I now need to find submatrixes 3x3 around every element (so each element in turn is the center of a…
Steeven
  • 4,057
  • 8
  • 38
  • 68
4
votes
1 answer

How to get all submatrices of given size in numpy?

For example, x = np.random.randint(low=0, high=10, shape=(6,6)) gives me a 6x6 numpy array: array([[3, 1, 0, 1, 5, 4], [2, 9, 9, 4, 8, 8], [2, 3, 4, 3, 2, 9], [5, 8, 4, 5, 7, 6], [3, 0, 8, 1, 8, 0], [6, 7, 1, 9, 0,…
Fequish
  • 705
  • 6
  • 17
4
votes
3 answers

Octave: Multiple submatrices from a matrix

I have a large matrix from which I would like to gather a collection of submatrices. If my matrix is NxN and the submatrix size is MxM, I want to collect I=(N - M + 1)^2 submatrices. In other words I want one MxM submatrix for each element in the…
fbrereto
  • 35,429
  • 19
  • 126
  • 178
4
votes
1 answer

Maximal sum of submatrix NxN matrix and with N-nonzero values, only O(N^2)

Suppose you have an N × N matrix where each row has exactly one nonzero element and each column has exactly one nonzero element (the nonzero elements can be either positive or negative). We want to find the maximum-sum submatrix. How efficiently can…
Khurshid
  • 2,654
  • 2
  • 21
  • 29
3
votes
1 answer

Removing columns from a "big.matrix" gives error: "cannot allocate vector of size 37.6 Gb"

I have a large "big.matrix" and I need to remove a few columns from it. It was created from a CSV file (with 72 million rows) using BigMat <- read.big.matrix("matrix.csv", type="double", header=TRUE, backingfile="matrix.bin", …
fil0607
  • 101
  • 5
3
votes
0 answers

Efficiently selecting non-contiguous columns of a sparse matrix in Rcpp-Armadillo

I am facing a seemingly simple task, but I am struggling to find an efficient way to do it. In Armadillo, I have defined a sparse matrix (sp_mat) of which I want to extract a number of non-contiguous columns. Unfortunately, sparse matrices do not…
3
votes
2 answers

How can I create submatrices

I understand that I can extract submatrices from an already created matrix but I want to be able to create submatrices first then combine the created submatrices to form a bigger matrix to save space and time. For example in my example, I want to be…
Viktor
  • 47
  • 5
1
2 3
12 13