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
2
votes
3 answers

Finding biggest negative submatrix in python

I want find the biggest submatrix which contains only negative numbers in a matrix, for example: In [[1, -9, -2, 8, 6, 1], [8, -1,-11, -7, 6, 4], [10, 12, -1, -9, -12, 14], [8, 10, -3, -5, 17, 8], [6, 4, 10, -13,…
IHav
  • 117
  • 7
2
votes
1 answer

Matrix without a particular submatrix in R

I have randomly generated a submatrix “train” from “mat” using the following: train <- mat[sample(nrow(mat), size = 317, replace = FALSE),] My question is, how do I then create “test” as a submatrix of “mat” which excludes the matrix “train”?…
TuringTester69
  • 177
  • 1
  • 9
2
votes
4 answers

Extracting every n-th column from matrix

I need to extract every n-th column from my matrix. For example I have a matrix: A = 1 23 34 53 67 45 67 45 12 34 45 56 67 87 98 12 1 2 3 45 56 76 87 56 And I want to…
Aybars
  • 395
  • 2
  • 11
2
votes
1 answer

Fast way to get all sub-matrices A[1:mid, (mid+1):n]

Given a matrix A of dimension n x n, my objective is to get all submatrices A[1:mid, (mid+1):n] and convert them as a list of vectors. Here mid runs from 1 to n-1. For example, if A = matrix(1:16, 4, 4), then the result will be res =…
yliueagle
  • 1,191
  • 1
  • 7
  • 22
2
votes
3 answers

Fast way to extract submatrix from numpy matrix

I have a huge .csv file (~2GB) that I import in my program with read_csvand then convert to an numpy matrix with as_matrix. The generated matrix has the form like the data_mat in the given example below. My problem is now, that I need to extract the…
nerdizzle
  • 424
  • 4
  • 17
2
votes
2 answers

How can we print all sub matrices of a given 2D matrix in Java?

Suppose I have a matrix of size, say 5*6. I need all the sub matrices, that is, of size 1*1, 1*2, 2*5,3*2,5*4 etc. How do I obtain it? for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { int arr[][] = new int[i + 1][j + 1]; for (x = 0; x < i +…
2
votes
1 answer

Better way to extract all the rows from a Matrix A that contain an element of a matrix B

Matrix A is my starting matrix it holds the data logged from my MPU6050 and GPS on an SD Card (Latitude, Longitude, Time, Ax, Ay, Az, Gx,Gy,Gz). I calculated the standard deviation of Az for window size of 5 and identified all the elements that…
Andrea Ciufo
  • 359
  • 1
  • 3
  • 19
2
votes
0 answers

Update submatrix in Tensorflow

Quite simply, what I want to do is the following A = np.ones((3,3)) #arbitrary matrix B = np.ones((2,2)) #arbitrary matrix A[1:,1:] = A[1:,1:] + B except in Tensorflow (where the matrices can be arbitrarily complicated tensor expressions). Neither…
Bonnevie
  • 187
  • 9
2
votes
1 answer

Make a matrix from submatrix in R

I need to make a matrix in R with its elements are from matrices I defined before. For example, I have 4 matrices, w <- matrix(c(1,2,3,4),2,2) x <- matrix(c(5,6,7,8),2,2) y <- matrix(c(9,10,11,12),2,2) z <- matrix(c(13,14,15,16),2,2) Then, the new…
2
votes
1 answer

Get a sub image using opencv Java

I have already looked at how to get sub image by using OpenCV in java api, but this did not help I am curious how to create a sub image of a Mat image that I have loaded in from a file. When I run: crop = img.submat(405, 450, 280, 335); I get : …
Ian
  • 21
  • 1
  • 4
2
votes
1 answer

Eigen3: extract a submatrix with a non constant number of columns

I wrote the following function in C++, using Eigen3: MatrixXf transformPoints(MatrixXf X, MatrixXf P) { // create a new matrix to host points MatrixXf tempMatrix = MatrixXf::Zero(4, P.cols()); // extract rotational and traslational…
ubisum
  • 179
  • 3
  • 12
2
votes
2 answers

Extratcing all square submatrices from matrix using Numpy

Say I have a NxN numpy matrix. I am looking for the fastest way of extracting all square chunks (sub-matrices) from this matrix. Meaning all CxC parts of the original matrix for 0 < C < N+1. The sub-matrices should correspond to contiguous…
2
votes
2 answers

Select submatrix and vectorize in one command in MATLAB

Lets say we have an Array A = ones(2, 2, 2) and another matrix P = rand(4). I am wondering if it is possible to write the code temp = A(:, :, 1); X = P * temp(:); into one line of code to save the memory consumed by temp. I tried to run X = P *…
awaelchli
  • 796
  • 7
  • 23
2
votes
1 answer

partition a matrix into matrix of blocks

I want to divide an image data into blocks, for example if I have X matrix of 4*4, I want the result to be a matrix M of 2*2*2*2 where M(1,1,:,:)=X(1:2,1:2) and M(1,2,:,:)=X(1:2,3:4) and etc. I found a way to divide it into a cell array using…
niceman
  • 2,653
  • 29
  • 57
2
votes
1 answer

Submatrix based on size vector

It seems like this problem should be common, but I haven't found a good duplicate... I'm implementing a level 2 S-function with a variable-sized multidimensional output. The state has to be in fixed-size Dwork vectors, so I zero-pad the input matrix…
Katie
  • 1,260
  • 10
  • 20
1 2
3
12 13