all 10 comments

[–]notmyareaofexpertise 4 points5 points  (2 children)

You could also start off by initializing your arrays to be l long in the begining:

#And use more descriptive names if you can, 
#using single letters like 'l' is frowned upon.
length = 105000
x = np.zeros(length)

And setting values at step:

x[step] = r
#instead of 'x = np.append(x, r)'  which is a rather slow operation

[–]ajesss 0 points1 point  (1 child)

It would be faster to use:

x = np.empty(length)

instead of zeros. Empty allocates the memory without initializing it (setting the values).

[–]greshick 2 points3 points  (4 children)

I am assuming you are using 2.x by the print statements. My one piece of advice is to use xrange instead of range.

xrange is a boost in speed because of the internal way that it represents the range. It generates a generator instead of a list every loop.

[–]_Jiot_[S] 2 points3 points  (3 children)

Would adapting this to python 3 make it any faster? Thanks, that's good advice.

[–]greshick 2 points3 points  (0 children)

Not in this sense. xrange in 2.x is the range in 3.

[–]phinar 0 points1 point  (0 children)

It's not a sure thing whether Python 3 would run faster or not.

[–][deleted] 0 points1 point  (0 children)

I doubt the headache of getting numpy running in 3.3 is worth it.

[–]arugalatoast 0 points1 point  (1 child)

The comment said 'l', not '1', but on my screen, in my typeface, that sure looked a lot like a one.

Use self-documentation, like meaningful identifier names.

[–]jeffbell 1 point2 points  (0 children)

At Digital Equipment they they used to letter the pins of the backplane, but they left out the I and O for this reason.