[SciPy-user] Avoiding For Loops Question

Ivo Maljevic ivo.maljevic at gmail.com
Fri Jun 5 14:05:22 EDT 2009


I know, sorry, you have already responded to this question. I fired my
question to fast.
Thanks,
Ivo

2009/6/5 Whitcomb, Mr. Tim <tim.whitcomb at nrlmry.navy.mil>:
>> Tim,
>> Just out of curiosity, why:
>>
>> > i = numpy.arange(len(x))
>> > a[:] = i[:]*(i[:]+1)/2*x[:]
>>
>> and not:
>>
>> > i = numpy.arange(len(x))
>> > a = i*(i+1)/2*x
>>
>> Ivo
>>
>
> Because I'm used to doing this in some of my Fortran 90 code, and I
> wasn't sure what the "right" way is to do it in Numpy/Scipy.  See
> Josef's notes on this thread - he writes "[t]o write flexible code it is
> better to leave [the [:] parts] off if they are not necessary."  Given
> that, the second version is the "better" of the functionally equivalent
> pair.
>
> Tim
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list