On Thursday 03 July 2008 15:53, Brain Stormer wrote: > I am using numpy to create an array then filling some of the values > using a for loop, I was wondering if there is way to easily fill > the values without iterating through sort of like > "array.fill[start:stop,start:stop]"? The reason for my question > is, in some cases, I might have to fill hundreds (within a > 10,000x10,000 matrix) of values and I am not sure if iteration is > the right way to go.
You can do it this way: >>> from numpy import * >>> m = zeros((5,5), int) >>> m[1:4, 1:4] = 1 >>> m array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]) HTH, Eike. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor