This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author LambertDW
Recipients LambertDW
Date 2008-01-21.02:58:49
SpamBayes Score 0.045208268
Marked as misclassified No
Message-id <>
Please generalize math.hypot.  While I don't have a survey of python 
codes, it seems to me unlikely for this change to break existing 

import math

def hypot(*args):
        Return the Euclidean vector length.
        >>> from math import hypot, sqrt
        >>> hypot(5,12)    # traditional definition
        >>> hypot()
        >>> hypot(-6.25)
        >>> hypot(1,1,1) == sqrt(3) # diagonal of unit box
    return math.sqrt(sum(arg*arg for arg in args))

I propose this version as closest to:
>>> print sys.version
2.5.1 (r251:54863, Jan  4 2008, 17:15:14) 
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)]
>>> print math.hypot.__doc__

Return the Euclidean distance, sqrt(x*x + y*y).


PS.  I don't understand why python is so restrictive.  Although hypot 
is in the math library, it could be written in EAFP style as

def hypot(*args):
    return sum(arg*arg for arg in args)**0.5

Rather than review the entire python library for items to generalize, 
I'll accept that the resulting errors would confuse "the penguin on my 
tele".  "hypot" crosses me most often.  I've not yet needed a version 
in the complex domain, such as my second version.

I typically fill my need for length with scipy.sqrt(,v)), 
only to realize that for the short vectors I use, standard python 
constructs always perform faster than scipy
Date User Action Args
2008-01-21 02:58:52LambertDWsetspambayes_score: 0.0452083 -> 0.045208268
recipients: + LambertDW
2008-01-21 02:58:52LambertDWsetspambayes_score: 0.0452083 -> 0.0452083
messageid: <>
2008-01-21 02:58:51LambertDWlinkissue1880 messages
2008-01-21 02:58:49LambertDWcreate