2

It's known that we can use the library to detect the array:

matrix_rank(A)

Then it will return the rank of this matrix. I got my rank for A is : 1450

However, it's in fact 1465 columns in the array. Then my problem is: how to delete those 15 columns that are the rubbish of this array? Is there any way to solve this issue?

Like for example,

G = [ -1  0  0  0 ]   
    [  0 -1  0  0 ]       
    [  0  0 -1 -1 ]       
    [ -1 -1  0  0 ]    

The last column is rubbish because it's the sum of the first two lines.

So is there any library that can help us to delete the column in python?

Zhang Zening
  • 65
  • 1
  • 7

1 Answers1

2

Your question is equivalent to asking which columns are linearly dependent.

This is very well studied. Here's a random example cropping up on math exchange. Here's a discussion on mathworks for strategies (in matlab, but applicable globally). Here's a similar question on this site. And a similar one using numpy and python, directly ansering your question

It would be silly to try and enumerate all the strategies of solving this problem here, since it's so fundamental to linear algebra, but that last author suggests the eigenvalue method. Quoting:

lambdas, V =  np.linalg.eig(matrix.T)
# The linearly dependent row vectors 
print matrix[lambdas == 0,:]

And cauchy-schwartz, which is a pane in the neck. If you follow the mathworks' link advice, you can use a QR decomposition

There's a great discussion of special cases of this problem here

Community
  • 1
  • 1
en_Knight
  • 5,301
  • 2
  • 26
  • 46
  • actually I know my array is linearly dependent at some columns. However, do you have any idea to modify or delete some columns that make my array linearly independent? – Zhang Zening Mar 23 '16 at 16:26
  • @ZhangZening that's a little vaugue for me; you could add a random number to each an entry in one of the dependent columns, or you could approximate it as a full rank matrix. But unless you have a metric for similarity, there are infinite ways to get a different matrix that is full rank (as there are infinite full rank matrices of that size). Is your probalme constrained? – en_Knight Mar 23 '16 at 17:26
  • If so, maybe look here http://math.stackexchange.com/questions/564603/probability-that-a-random-binary-matrix-will-have-full-column-rank, otherwise http://stackoverflow.com/questions/20409899/construct-a-full-rank-matrix-by-adding-vectors-from-the-standard-basis and http://stackoverflow.com/questions/10123771/make-a-matrix-full-ranked offer some solutions, but again that's too broad to address in one blow – en_Knight Mar 23 '16 at 17:26
  • Thanks for your work! I see the links and it's very close to what I want. Actually I do not add new data in my array to get it works. I just want to delete those columns that make our array in a not full-rank array. – Zhang Zening Mar 23 '16 at 21:09