[SciPy-User] python lists in combination with numpy arrays

Martin van Leeuwen vanleeuwen.martin@gmail....
Wed Nov 10 16:36:50 CST 2010


Yeah, thanks a lot Corran. Totally understandable now.

Martin
----
I'll have a coffee..


2010/11/10 Corran Webster <cwebster@enthought.com>:
> Hi Martin,
>
> there is another difference:
>
> On Wed, Nov 10, 2010 at 3:25 PM, Martin van Leeuwen
> <vanleeuwen.martin@gmail.com> wrote:
>>
>> print "first method"
>>
>> lst=[]
>> a = numpy.zeros(3, dtype=float)
>> for i in range(2):
>> ...
>
> here you are creating one array, and overwriting the values in it in your
> loop.
>
>
>>
>> print "second method"
>>
>> lst=[]
>> for i in range(2):
>>    a = numpy.random.rand(3)
>
> here you are creating two different arrays.
>
> If you move the line  a = numpy.zeros(3, dtype=float) into the for loop in
> the first example, you should get the same result.
>
> -- Corran
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>


More information about the SciPy-User mailing list