Skip to content

Instantly share code, notes, and snippets.

@svschannak
Created January 19, 2014 19:43
Show Gist options
  • Save svschannak/8510014 to your computer and use it in GitHub Desktop.
Save svschannak/8510014 to your computer and use it in GitHub Desktop.
Calculate ratio with Python and Numpy.
#calculates r for height and width
def ratio(a, b):
a = float(a)
b = float(b)
if b == 0:
return a
return ratio(b, a % b)
#returns a string with ratio for height and width
def get_ratio(a, b):
r = ratio(a, b)
return "%s" % float((a/r) / (b/r))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment