[SciPy-user] Avoiding For Loops Question
Whitcomb, Mr. Tim
tim.whitcomb at nrlmry.navy.mil
Fri Jun 5 14:19:59 EDT 2009
> > All right guys, last one:
> >
> > for l in xrange(1,1000):
> > for m in xrange(0,l+1):
> > Alm[l][m] = alm[l][m]*cl[l]
> > Blm[l][m] =alm[l][m]*cl[l]
> >
> > Here is one where the second index depends on value of the first.
>
> In this case, you are still summing across columns (i.e. the
> first index of all parts of the expression is constant). The
> only variation is that in row N, you only want the first N
> columns. The output pattern that you get from your for loop
> looks like:
> x
> x x
> x x x
> ...
> which, in a rectangular matrix, means that it's lower
> triangular, so you can do something like:
Whoops - got the signs mixed up. This should be
A = numpy.tril(alm * cl[:,numpy.newaxis])
Tim
More information about the SciPy-User
mailing list