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

Martin van Leeuwen vanleeuwen.martin at gmail.com
Wed Nov 10 17:36:50 EST 2010


Yeah, thanks a lot Corran. Totally understandable now.

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


2010/11/10 Corran Webster <cwebster at enthought.com>:
> Hi Martin,
>
> there is another difference:
>
> On Wed, Nov 10, 2010 at 3:25 PM, Martin van Leeuwen
> <vanleeuwen.martin at 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 at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>



More information about the SciPy-User mailing list