Skip to content

Instantly share code, notes, and snippets.

@travisbrady
Created May 1, 2014 15:27
Show Gist options
  • Save travisbrady/8ef48f8e28f8087d1f8e to your computer and use it in GitHub Desktop.
Save travisbrady/8ef48f8e28f8087d1f8e to your computer and use it in GitHub Desktop.
linspace.rb
def linspace(start, stop, num=50, endpoint=true)
start_f = start.to_f
stop_f = stop.to_f
step = (stop_f - start_f) / (num.to_f - (endpoint ? 1.0 : 0.0))
i = 1
n = num - 1
result = [start_f]
while i < n
result.push(result.last + step)
i += 1
end
result.push(stop)
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment