Skip to content

Instantly share code, notes, and snippets.

@MattWoodhead
Created September 13, 2017 18:36
Show Gist options
  • Save MattWoodhead/d5b6aabf8521b1162b745ee5a7a4c5d5 to your computer and use it in GitHub Desktop.
Save MattWoodhead/d5b6aabf8521b1162b745ee5a7a4c5d5 to your computer and use it in GitHub Desktop.
"""
Generator function for creating a range of floating point numbers
Numpy linspace is probably better unless you cannot have imports!!
"""
def frange(start, stop, step, precision=10):
""" a range generator that accepts floats """
k = start
while k < stop:
yield round(k, precision)
k += step
if __name__ == "__main__":
print(list(frange(0.1, 0.9, 0.2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment