Numeric python question: How do I zero all elements of a matrix 0 ?
Ram Bhamidipaty
ramb at sonic.net
Tue Oct 15 14:45:25 EDT 2002
Carl Banks <imbosol at vt.edu> writes:
> 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
>
COOL!! Thank you! I knew there would be a nice Python way
to do this.
-Ram
More information about the Python-list
mailing list