[Numpy-discussion] Easter Egg or what I am missing here?

alex argriffi at ncsu.edu
Wed May 21 15:38:16 EDT 2014


On Wed, May 21, 2014 at 3:29 PM, Siegfried Gonzi
<siegfried.gonzi at ed.ac.uk> wrote:
> Please would anyone tell me the following is an undocumented bug
> otherwise I will lose faith in everything:
>
> ==
> import numpy as np
>
>
> years = [2004,2005,2006,2007]
>
> dates = [20040501,20050601,20060801,20071001]
>
> for x in years:
>
>      print 'year ',x
>
>      xy =  np.array([x*1.0e-4 for x in dates]).astype(np.int)
>
>      print 'year ',x
> ==
>


It seems like a misunderstanding of Python scoping, or just an
oversight in your code, or I'm not understanding your question.  Would
you expect the following code to print the same value twice in each
iteration?

for x in (1, 2, 3):
    print x
    dummy = [x*x for x in (4, 5, 6)]
    print x
    print


> Or is this a recipe to blow up a power plant?

Now we're on the lists...


Cheers!



More information about the NumPy-Discussion mailing list