submatrix

slicing sparse (scipy) matrix

倾然丶 夕夏残阳落幕 提交于 2019-12-03 05:12:02
问题 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 lines of code: x1 = A[list 1,:] x2 = x1[:,list 2] Everything was fine and I could extract the right submatrix. When I tried to do this in one line, it failed (The returning matrix was empty) x=A[list 1,list 2] Why is this so? Overall, I have used

slicing sparse (scipy) matrix

被刻印的时光 ゝ 提交于 2019-12-02 19:38:28
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 lines of code: x1 = A[list 1,:] x2 = x1[:,list 2] Everything was fine and I could extract the right submatrix. When I tried to do this in one line, it failed (The returning matrix was empty) x=A[list 1,list 2] Why is this so? Overall, I have used a similar command in matlab and there it works. So, why not use the first, since it works? It seems to

Finding a submatrix with the maximum possible sum in O(n^2)

浪子不回头ぞ 提交于 2019-12-02 01:14:37
问题 I'm trying to write a program in Java that when given an MxN matrix it will find the (contiguous) submatrix with the biggest sum of numbers. The program then needs to return the top left corner coordinates of the submatrix and the bottom right corner coordinates. The matrix can include negative numbers and both the matrix and submatrix don't need to be square. I saw that this was discussed here: Getting the submatrix with maximum sum? and the solution there seems to be O(n^3). A friend of

Finding a submatrix with the maximum possible sum in O(n^2)

僤鯓⒐⒋嵵緔 提交于 2019-12-01 21:28:32
I'm trying to write a program in Java that when given an MxN matrix it will find the (contiguous) submatrix with the biggest sum of numbers. The program then needs to return the top left corner coordinates of the submatrix and the bottom right corner coordinates. The matrix can include negative numbers and both the matrix and submatrix don't need to be square. I saw that this was discussed here: Getting the submatrix with maximum sum? and the solution there seems to be O(n^3). A friend of mine said that they had once managed to solve this problem in O(n^2). Also suggested here. Is that

Finding sub matrix of a given matrix

点点圈 提交于 2019-12-01 11:04:08
i am trying to write an algorithm for finding a sub matrix in a given sub matrix. To solve this problem i had written the following code: public class SubMatTry { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int a[][] = { { 2, 3, 5, 7 }, { 5, 8, 3, 5 }, { 7, 6, 9, 2 }, { 3, 8, 5, 9 } }; int b[][] = { { 9, 2 }, { 5, 9 } }; int k = 0; int l = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { System.out.println("Element of a= " + a[i][j]); if (b[k][l] == a[i][j]) { System.out.println(b[k][l] + " = " + a[i][j]); if (b[k][l + 1] == a

How to extract a 2x2 submatrix from a bigger matrix

断了今生、忘了曾经 提交于 2019-11-30 09:54:19
问题 I am a very basic user and do not know much about commands used in C, so please bear with me...I cant use very complicated codes. I have some knowledge in the stdio.h and ctype.h library, but thats about it. I have a matrix in a txt file and I want to load the matrix based on my input of number of rows and columns For example, I have a 5 by 5 matrix in the file. I want to extract a specific 2 by 2 submatrix, how can I do that ? I created a nested loop using : FILE *sample sample=fopen(

How to extract a 2x2 submatrix from a bigger matrix

浪尽此生 提交于 2019-11-29 17:48:02
I am a very basic user and do not know much about commands used in C, so please bear with me...I cant use very complicated codes. I have some knowledge in the stdio.h and ctype.h library, but thats about it. I have a matrix in a txt file and I want to load the matrix based on my input of number of rows and columns For example, I have a 5 by 5 matrix in the file. I want to extract a specific 2 by 2 submatrix, how can I do that ? I created a nested loop using : FILE *sample sample=fopen("randomfile.txt","r"); for(i=0;i<rows;i++){ for(j=0;j<cols;j++){ fscanf(sample,"%f",&matrix[i][j]); } fscanf

Select rows of a matrix that meet a condition

那年仲夏 提交于 2019-11-27 10:01:32
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: one two three four [1,] 1 6 11 16 [3,] 3 8 11 18 [4,] 4 9 11 19 I want to do this without looping. I am new to R so this is probably very obvious but the documentation is often somewhat terse. This is easier to do if you convert your matrix to a data frame using as.data.frame(). In that case the previous answers (using subset or m$three) will work, otherwise they will not. To perform the operation on a

Getting the submatrix with maximum sum?

ぐ巨炮叔叔 提交于 2019-11-26 18:18:35
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 the help of the Algorithmist, Larry and a modification of Kadane's Algorithm, i managed to solve the problem partly which is determining the summation only - below in Java. Thanks to Ernesto who managed to solve the rest of the problem which is determining the boundaries of the matrix i.e. top-left, bottom-right corners - below in Ruby. Ernesto

Select rows of a matrix that meet a condition

你说的曾经没有我的故事 提交于 2019-11-26 10:06:30
问题 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: one two three four [1,] 1 6 11 16 [3,] 3 8 11 18 [4,] 4 9 11 19 I want to do this without looping. I am new to R so this is probably very obvious but the documentation is often somewhat terse. 回答1: This is easier to do if you convert your matrix to a data frame using as.data.frame(). In that case the