Numeric python question: How do I zero all elements of a matrix 0 ?
Carl Banks
imbosol at vt.edu
Mon Oct 14 19:28:12 EDT 2002
Ram Bhamidipaty wrote:
> I have a matrix created with the Numeric package,
> I want to keep reusing the same matrix, in order to
> do this I need to zero out all the elements.
>
> I know I could write a loop like this:
>
> # my arrays are two dimensional
> t = M.shape
> for x in range(0,t[0]):
> for y in range(0,t[1]):
> M[x,y] = 0.0
>
> But I have a feeling that this would be very slow. Is
> there a special function that I can use to do this?
M[:] = 0.0
--
CARL BANKS
http://www.aerojockey.com
More information about the Python-list
mailing list