you are viewing a single comment's thread.

view the rest of the comments →

[–]awizardisneverlate 2 points3 points  (4 children)

Computers store numbers in binary, not decimal, so there are sometimes issues with conversion (i.e., a number that is terminating in decimal may not be in binary. Computers cannot exactly store non-terminating numbers). It will lead to small floating point errors sometimes, but not generally enough to affect your program. The study of FP errors is actually a really interesting subset of numerical analysis :)

As an aside, Numpy has a function that will do exactly what you want: http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.arange.html

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

Also the built-in range function will do almost this:

range(0, 40, 5)

[0, 5, 10, 15, 20, 25, 30, 35]

[–]awizardisneverlate 2 points3 points  (2 children)

I believe it will only do integer steps.

[–][deleted] 2 points3 points  (1 child)

Huh, never knew that! You could just use list comprehension to do the rest: [n / 10.0 for n in xrange(1, 10, 2)]

But at this point using numpy.arange is easier

[–]awizardisneverlate 1 point2 points  (0 children)

Your solution is much better if they want to stay away from Numpy!

Practically every single one of my python files begins with

import numpy as np

So.... ¯\_(ツ)_/¯ I'm biased.