[SciPy-User] python lists in combination with numpy arrays
Corran Webster
cwebster at enthought.com
Wed Nov 10 17:19:36 EST 2010
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20101110/89559453/attachment.html>
More information about the SciPy-User
mailing list