SUB-MATRIX extraction

P

Pierre

Hello,


let b = array([ [0,1,2] , [3,4,5] , [6,7,8] ])

How can I easily extract the submatrix [ [0 ,1], [3, 4]] ?

One possiblity is : b[[0,1],:][:,[0,1]] but it is not really easy !

Thanks.
 
M

Martin P. Hellwig

Jon said:
Hello,

let b = array([ [0,1,2] , [3,4,5] , [6,7,8] ])

How can I easily extract the submatrix [ [0 ,1], [3, 4]] ?

One possiblity is : b[[0,1],:][:,[0,1]] but it is not really easy !

Thanks.

x = numpy.array([ [0,1,2], [3,4,5], [6,7,8] ])
print x[0:2,:2]
[3, 4]])

Check out http://www.scipy.org/Tentative_NumPy_Tutorial

hth,

Jon.

Yeah numpy is great like that and is the most obvious and probably the
most right solution, however I'd like to mention if you are going to do
a lot of stuff that is going to look an awful lot like SQL, perhaps it
is easier to pump it in a (in :memory:) sqlite table and use it that
way. Chances are though that you are far better of with numpy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,518
Latest member
RomanGratt

Latest Threads

Top