help with slicing/replacing matrix sections.
elind at spamcop.net
Mon Jan 14 20:25:29 CET 2008
I see a more complicated thread on a similar sounding question, but my
question is simpler, I hope.
I have a large numpy matrix, initially created as:
Mat = zeros((a,b), int)
and a smaller array with other data
Sub = [1,2,3,4,5],[6,7,8,9,0]
I want to replace a section of Mat matrix with Sub matrix without having to
loop through each cell in each matrix individually.
I thought index/slice assignments, should be able to do that, but I can only
get it to work (as per book examples) with simple arrays. Every syntax
combination I have tried gives one error or another, typically "can't
broadcast an object....", but intuitively it seems there should be a simple
In short, how do I insert the data in the two (or any number of) rows in
Sub[0:2] into any part of Mat starting at Mat[x,y] without using "for" loops
More information about the Python-list