[Numpy-discussion] syntax for obtaining rank of two columns?

Tim Hochberg tim.hochberg at cox.net
Thu Jun 15 19:27:42 CDT 2006


JJ wrote:

>Hello.  I am a matlab user learning the syntax of
>numpy.  Id like to check that I am not missing some
>easy steps on column selection and concatenation.  The
>example task is to determine if two columns selected
>out of an array are of full rank (rank 2).  Lets say
>we have an array d that is size (10,10) and we select
>the ith and jth columns to test their rank.  In matlab
>the command is quite simple:
>
>rank([d(:,i),d(:,j)])
>
>In numpy, the best I have thought of so far is:
>
>linalg.lstsq(transpose(vstack((d[:,i],d[:,j]))), \
>ones((shape(transpose(vstack((d[:,i],d[:,j]))))  \
>[0],1),'d'))[2]
>
>Im thinking there must be a less awkward way.  Any
>ideas?  
>  
>
This isn't really my field, so this could be wrong, but try:

linalg.lstsq(d[:,[i,j]], ones_like(d[:,[i,j]]))[2]

and see if that works for you.

-tim

>JJ
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam?  Yahoo! Mail has the best spam protection around 
>http://mail.yahoo.com 
>
>
>_______________________________________________
>Numpy-discussion mailing list
>Numpy-discussion at lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
>
>  
>






More information about the Numpy-discussion mailing list