doc_content stringlengths 1 386k | doc_id stringlengths 5 188 |
|---|---|
math — Mathematical functions This module provides access to the mathematical functions defined by the C standard. These functions cannot be used with complex numbers; use the functions of the same name from the cmath module if you require support for complex numbers. The distinction between functions which support com... | python.library.math |
math.acos(x)
Return the arc cosine of x, in radians. The result is between 0 and pi. | python.library.math#math.acos |
math.acosh(x)
Return the inverse hyperbolic cosine of x. | python.library.math#math.acosh |
math.asin(x)
Return the arc sine of x, in radians. The result is between -pi/2 and pi/2. | python.library.math#math.asin |
math.asinh(x)
Return the inverse hyperbolic sine of x. | python.library.math#math.asinh |
math.atan(x)
Return the arc tangent of x, in radians. The result is between -pi/2 and pi/2. | python.library.math#math.atan |
math.atan2(y, x)
Return atan(y / x), in radians. The result is between -pi and pi. The vector in the plane from the origin to point (x, y) makes this angle with the positive X axis. The point of atan2() is that the signs of both inputs are known to it, so it can compute the correct quadrant for the angle. For example... | python.library.math#math.atan2 |
math.atanh(x)
Return the inverse hyperbolic tangent of x. | python.library.math#math.atanh |
math.ceil(x)
Return the ceiling of x, the smallest integer greater than or equal to x. If x is not a float, delegates to x.__ceil__(), which should return an Integral value. | python.library.math#math.ceil |
math.comb(n, k)
Return the number of ways to choose k items from n items without repetition and without order. Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates to zero when k > n. Also called the binomial coefficient because it is equivalent to the coefficient of k-th term in polynomial expansion of the ex... | python.library.math#math.comb |
math.copysign(x, y)
Return a float with the magnitude (absolute value) of x but the sign of y. On platforms that support signed zeros, copysign(1.0, -0.0) returns -1.0. | python.library.math#math.copysign |
math.cos(x)
Return the cosine of x radians. | python.library.math#math.cos |
math.cosh(x)
Return the hyperbolic cosine of x. | python.library.math#math.cosh |
math.degrees(x)
Convert angle x from radians to degrees. | python.library.math#math.degrees |
math.dist(p, q)
Return the Euclidean distance between two points p and q, each given as a sequence (or iterable) of coordinates. The two points must have the same dimension. Roughly equivalent to: sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))
New in version 3.8. | python.library.math#math.dist |
math.e
The mathematical constant e = 2.718281…, to available precision. | python.library.math#math.e |
math.erf(x)
Return the error function at x. The erf() function can be used to compute traditional statistical functions such as the cumulative standard normal distribution: def phi(x):
'Cumulative distribution function for the standard normal distribution'
return (1.0 + erf(x / sqrt(2.0))) / 2.0
New in vers... | python.library.math#math.erf |
math.erfc(x)
Return the complementary error function at x. The complementary error function is defined as 1.0 - erf(x). It is used for large values of x where a subtraction from one would cause a loss of significance. New in version 3.2. | python.library.math#math.erfc |
math.exp(x)
Return e raised to the power x, where e = 2.718281… is the base of natural logarithms. This is usually more accurate than math.e ** x or pow(math.e, x). | python.library.math#math.exp |
math.expm1(x)
Return e raised to the power x, minus 1. Here e is the base of natural logarithms. For small floats x, the subtraction in exp(x) - 1 can result in a significant loss of precision; the expm1() function provides a way to compute this quantity to full precision: >>> from math import exp, expm1
>>> exp(1e-5... | python.library.math#math.expm1 |
math.fabs(x)
Return the absolute value of x. | python.library.math#math.fabs |
math.factorial(x)
Return x factorial as an integer. Raises ValueError if x is not integral or is negative. Deprecated since version 3.9: Accepting floats with integral values (like 5.0) is deprecated. | python.library.math#math.factorial |
math.floor(x)
Return the floor of x, the largest integer less than or equal to x. If x is not a float, delegates to x.__floor__(), which should return an Integral value. | python.library.math#math.floor |
math.fmod(x, y)
Return fmod(x, y), as defined by the platform C library. Note that the Python expression x % y may not return the same result. The intent of the C standard is that fmod(x, y) be exactly (mathematically; to infinite precision) equal to x - n*y for some integer n such that the result has the same sign a... | python.library.math#math.fmod |
math.frexp(x)
Return the mantissa and exponent of x as the pair (m, e). m is a float and e is an integer such that x == m * 2**e exactly. If x is zero, returns (0.0, 0), otherwise 0.5 <= abs(m) < 1. This is used to “pick apart” the internal representation of a float in a portable way. | python.library.math#math.frexp |
math.fsum(iterable)
Return an accurate floating point sum of values in the iterable. Avoids loss of precision by tracking multiple intermediate partial sums: >>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
0.9999999999999999
>>> fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
1.0
The algorithm’s accuracy depends on... | python.library.math#math.fsum |
math.gamma(x)
Return the Gamma function at x. New in version 3.2. | python.library.math#math.gamma |
math.gcd(*integers)
Return the greatest common divisor of the specified integer arguments. If any of the arguments is nonzero, then the returned value is the largest positive integer that is a divisor of all arguments. If all arguments are zero, then the returned value is 0. gcd() without arguments returns 0. New in... | python.library.math#math.gcd |
math.hypot(*coordinates)
Return the Euclidean norm, sqrt(sum(x**2 for x in coordinates)). This is the length of the vector from the origin to the point given by the coordinates. For a two dimensional point (x, y), this is equivalent to computing the hypotenuse of a right triangle using the Pythagorean theorem, sqrt(x... | python.library.math#math.hypot |
math.inf
A floating-point positive infinity. (For negative infinity, use -math.inf.) Equivalent to the output of float('inf'). New in version 3.5. | python.library.math#math.inf |
math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)
Return True if the values a and b are close to each other and False otherwise. Whether or not two values are considered close is determined according to given absolute and relative tolerances. rel_tol is the relative tolerance – it is the maximum allowed difference be... | python.library.math#math.isclose |
math.isfinite(x)
Return True if x is neither an infinity nor a NaN, and False otherwise. (Note that 0.0 is considered finite.) New in version 3.2. | python.library.math#math.isfinite |
math.isinf(x)
Return True if x is a positive or negative infinity, and False otherwise. | python.library.math#math.isinf |
math.isnan(x)
Return True if x is a NaN (not a number), and False otherwise. | python.library.math#math.isnan |
math.isqrt(n)
Return the integer square root of the nonnegative integer n. This is the floor of the exact square root of n, or equivalently the greatest integer a such that a² ≤ n. For some applications, it may be more convenient to have the least integer a such that n ≤ a², or in other words the ceiling of the exact... | python.library.math#math.isqrt |
math.lcm(*integers)
Return the least common multiple of the specified integer arguments. If all arguments are nonzero, then the returned value is the smallest positive integer that is a multiple of all arguments. If any of the arguments is zero, then the returned value is 0. lcm() without arguments returns 1. New in... | python.library.math#math.lcm |
math.ldexp(x, i)
Return x * (2**i). This is essentially the inverse of function frexp(). | python.library.math#math.ldexp |
math.lgamma(x)
Return the natural logarithm of the absolute value of the Gamma function at x. New in version 3.2. | python.library.math#math.lgamma |
math.log(x[, base])
With one argument, return the natural logarithm of x (to base e). With two arguments, return the logarithm of x to the given base, calculated as log(x)/log(base). | python.library.math#math.log |
math.log10(x)
Return the base-10 logarithm of x. This is usually more accurate than log(x, 10). | python.library.math#math.log10 |
math.log1p(x)
Return the natural logarithm of 1+x (base e). The result is calculated in a way which is accurate for x near zero. | python.library.math#math.log1p |
math.log2(x)
Return the base-2 logarithm of x. This is usually more accurate than log(x, 2). New in version 3.3. See also int.bit_length() returns the number of bits necessary to represent an integer in binary, excluding the sign and leading zeros. | python.library.math#math.log2 |
math.modf(x)
Return the fractional and integer parts of x. Both results carry the sign of x and are floats. | python.library.math#math.modf |
math.nan
A floating-point “not a number” (NaN) value. Equivalent to the output of float('nan'). New in version 3.5. | python.library.math#math.nan |
math.nextafter(x, y)
Return the next floating-point value after x towards y. If x is equal to y, return y. Examples:
math.nextafter(x, math.inf) goes up: towards positive infinity.
math.nextafter(x, -math.inf) goes down: towards minus infinity.
math.nextafter(x, 0.0) goes towards zero.
math.nextafter(x, math.cop... | python.library.math#math.nextafter |
math.perm(n, k=None)
Return the number of ways to choose k items from n items without repetition and with order. Evaluates to n! / (n - k)! when k <= n and evaluates to zero when k > n. If k is not specified or is None, then k defaults to n and the function returns n!. Raises TypeError if either of the arguments are ... | python.library.math#math.perm |
math.pi
The mathematical constant π = 3.141592…, to available precision. | python.library.math#math.pi |
math.pow(x, y)
Return x raised to the power y. Exceptional cases follow Annex ‘F’ of the C99 standard as far as possible. In particular, pow(1.0, x) and pow(x, 0.0) always return 1.0, even when x is a zero or a NaN. If both x and y are finite, x is negative, and y is not an integer then pow(x, y) is undefined, and ra... | python.library.math#math.pow |
math.prod(iterable, *, start=1)
Calculate the product of all the elements in the input iterable. The default start value for the product is 1. When the iterable is empty, return the start value. This function is intended specifically for use with numeric values and may reject non-numeric types. New in version 3.8. | python.library.math#math.prod |
math.radians(x)
Convert angle x from degrees to radians. | python.library.math#math.radians |
math.remainder(x, y)
Return the IEEE 754-style remainder of x with respect to y. For finite x and finite nonzero y, this is the difference x - n*y, where n is the closest integer to the exact value of the quotient x /
y. If x / y is exactly halfway between two consecutive integers, the nearest even integer is used fo... | python.library.math#math.remainder |
math.sin(x)
Return the sine of x radians. | python.library.math#math.sin |
math.sinh(x)
Return the hyperbolic sine of x. | python.library.math#math.sinh |
math.sqrt(x)
Return the square root of x. | python.library.math#math.sqrt |
math.tan(x)
Return the tangent of x radians. | python.library.math#math.tan |
math.tanh(x)
Return the hyperbolic tangent of x. | python.library.math#math.tanh |
math.tau
The mathematical constant τ = 6.283185…, to available precision. Tau is a circle constant equal to 2π, the ratio of a circle’s circumference to its radius. To learn more about Tau, check out Vi Hart’s video Pi is (still) Wrong, and start celebrating Tau day by eating twice as much pie! New in version 3.6. | python.library.math#math.tau |
math.trunc(x)
Return the Real value x truncated to an Integral (usually an integer). Delegates to x.__trunc__(). | python.library.math#math.trunc |
math.ulp(x)
Return the value of the least significant bit of the float x: If x is a NaN (not a number), return x. If x is negative, return ulp(-x). If x is a positive infinity, return x. If x is equal to zero, return the smallest positive denormalized representable float (smaller than the minimum positive normalized... | python.library.math#math.ulp |
max(iterable, *[, key, default])
max(arg1, arg2, *args[, key])
Return the largest item in an iterable or the largest of two or more arguments. If one positional argument is provided, it should be an iterable. The largest item in the iterable is returned. If two or more positional arguments are provided, the largest... | python.library.functions#max |
exception MemoryError
Raised when an operation runs out of memory but the situation may still be rescued (by deleting some objects). The associated value is a string indicating what kind of (internal) operation ran out of memory. Note that because of the underlying memory management architecture (C’s malloc() functio... | python.library.exceptions#MemoryError |
class memoryview(obj)
Create a memoryview that references obj. obj must support the buffer protocol. Built-in objects that support the buffer protocol include bytes and bytearray. A memoryview has the notion of an element, which is the atomic memory unit handled by the originating object obj. For many simple types su... | python.library.stdtypes#memoryview |
class memoryview(obj)
Return a “memory view” object created from the given argument. See Memory Views for more information. | python.library.functions#memoryview |
cast(format[, shape])
Cast a memoryview to a new format or shape. shape defaults to [byte_length//new_itemsize], which means that the result view will be one-dimensional. The return value is a new memoryview, but the buffer itself is not copied. Supported casts are 1D -> C-contiguous and C-contiguous -> 1D. The desti... | python.library.stdtypes#memoryview.cast |
contiguous
A bool indicating whether the memory is contiguous. New in version 3.3. | python.library.stdtypes#memoryview.contiguous |
c_contiguous
A bool indicating whether the memory is C-contiguous. New in version 3.3. | python.library.stdtypes#memoryview.c_contiguous |
format
A string containing the format (in struct module style) for each element in the view. A memoryview can be created from exporters with arbitrary format strings, but some methods (e.g. tolist()) are restricted to native single element formats. Changed in version 3.3: format 'B' is now handled according to the s... | python.library.stdtypes#memoryview.format |
f_contiguous
A bool indicating whether the memory is Fortran contiguous. New in version 3.3. | python.library.stdtypes#memoryview.f_contiguous |
hex([sep[, bytes_per_sep]])
Return a string object containing two hexadecimal digits for each byte in the buffer. >>> m = memoryview(b"abc")
>>> m.hex()
'616263'
New in version 3.5. Changed in version 3.8: Similar to bytes.hex(), memoryview.hex() now supports optional sep and bytes_per_sep parameters to insert se... | python.library.stdtypes#memoryview.hex |
itemsize
The size in bytes of each element of the memoryview: >>> import array, struct
>>> m = memoryview(array.array('H', [32000, 32001, 32002]))
>>> m.itemsize
2
>>> m[0]
32000
>>> struct.calcsize('H') == m.itemsize
True | python.library.stdtypes#memoryview.itemsize |
nbytes
nbytes == product(shape) * itemsize == len(m.tobytes()). This is the amount of space in bytes that the array would use in a contiguous representation. It is not necessarily equal to len(m): >>> import array
>>> a = array.array('i', [1,2,3,4,5])
>>> m = memoryview(a)
>>> len(m)
5
>>> m.nbytes
20
>>> y = m[::2]
... | python.library.stdtypes#memoryview.nbytes |
ndim
An integer indicating how many dimensions of a multi-dimensional array the memory represents. | python.library.stdtypes#memoryview.ndim |
obj
The underlying object of the memoryview: >>> b = bytearray(b'xyz')
>>> m = memoryview(b)
>>> m.obj is b
True
New in version 3.3. | python.library.stdtypes#memoryview.obj |
readonly
A bool indicating whether the memory is read only. | python.library.stdtypes#memoryview.readonly |
release()
Release the underlying buffer exposed by the memoryview object. Many objects take special actions when a view is held on them (for example, a bytearray would temporarily forbid resizing); therefore, calling release() is handy to remove these restrictions (and free any dangling resources) as soon as possible... | python.library.stdtypes#memoryview.release |
shape
A tuple of integers the length of ndim giving the shape of the memory as an N-dimensional array. Changed in version 3.3: An empty tuple instead of None when ndim = 0. | python.library.stdtypes#memoryview.shape |
strides
A tuple of integers the length of ndim giving the size in bytes to access each element for each dimension of the array. Changed in version 3.3: An empty tuple instead of None when ndim = 0. | python.library.stdtypes#memoryview.strides |
suboffsets
Used internally for PIL-style arrays. The value is informational only. | python.library.stdtypes#memoryview.suboffsets |
tobytes(order=None)
Return the data in the buffer as a bytestring. This is equivalent to calling the bytes constructor on the memoryview. >>> m = memoryview(b"abc")
>>> m.tobytes()
b'abc'
>>> bytes(m)
b'abc'
For non-contiguous arrays the result is equal to the flattened list representation with all elements converte... | python.library.stdtypes#memoryview.tobytes |
tolist()
Return the data in the buffer as a list of elements. >>> memoryview(b'abc').tolist()
[97, 98, 99]
>>> import array
>>> a = array.array('d', [1.1, 2.2, 3.3])
>>> m = memoryview(a)
>>> m.tolist()
[1.1, 2.2, 3.3]
Changed in version 3.3: tolist() now supports all single character native formats in struct modul... | python.library.stdtypes#memoryview.tolist |
toreadonly()
Return a readonly version of the memoryview object. The original memoryview object is unchanged. >>> m = memoryview(bytearray(b'abc'))
>>> mm = m.toreadonly()
>>> mm.tolist()
[89, 98, 99]
>>> mm[0] = 42
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot modify read... | python.library.stdtypes#memoryview.toreadonly |
__eq__(exporter)
A memoryview and a PEP 3118 exporter are equal if their shapes are equivalent and if all corresponding values are equal when the operands’ respective format codes are interpreted using struct syntax. For the subset of struct format strings currently supported by tolist(), v and w are equal if v.tolis... | python.library.stdtypes#memoryview.__eq__ |
mimetypes — Map filenames to MIME types Source code: Lib/mimetypes.py The mimetypes module converts between a filename or URL and the MIME type associated with the filename extension. Conversions are provided from filename to MIME type and from MIME type to filename extension; encodings are not supported for the latter... | python.library.mimetypes |
mimetypes.add_type(type, ext, strict=True)
Add a mapping from the MIME type type to the extension ext. When the extension is already known, the new type will replace the old one. When the type is already known the extension will be added to the list of known extensions. When strict is True (the default), the mapping ... | python.library.mimetypes#mimetypes.add_type |
mimetypes.common_types
Dictionary mapping filename extensions to non-standard, but commonly found MIME types. | python.library.mimetypes#mimetypes.common_types |
mimetypes.encodings_map
Dictionary mapping filename extensions to encoding types. | python.library.mimetypes#mimetypes.encodings_map |
mimetypes.guess_all_extensions(type, strict=True)
Guess the extensions for a file based on its MIME type, given by type. The return value is a list of strings giving all possible filename extensions, including the leading dot ('.'). The extensions are not guaranteed to have been associated with any particular data st... | python.library.mimetypes#mimetypes.guess_all_extensions |
mimetypes.guess_extension(type, strict=True)
Guess the extension for a file based on its MIME type, given by type. The return value is a string giving a filename extension, including the leading dot ('.'). The extension is not guaranteed to have been associated with any particular data stream, but would be mapped to ... | python.library.mimetypes#mimetypes.guess_extension |
mimetypes.guess_type(url, strict=True)
Guess the type of a file based on its filename, path or URL, given by url. URL can be a string or a path-like object. The return value is a tuple (type, encoding) where type is None if the type can’t be guessed (missing or unknown suffix) or a string of the form 'type/subtype', ... | python.library.mimetypes#mimetypes.guess_type |
mimetypes.init(files=None)
Initialize the internal data structures. If given, files must be a sequence of file names which should be used to augment the default type map. If omitted, the file names to use are taken from knownfiles; on Windows, the current registry settings are loaded. Each file named in files or know... | python.library.mimetypes#mimetypes.init |
mimetypes.inited
Flag indicating whether or not the global data structures have been initialized. This is set to True by init(). | python.library.mimetypes#mimetypes.inited |
mimetypes.knownfiles
List of type map file names commonly installed. These files are typically named mime.types and are installed in different locations by different packages. | python.library.mimetypes#mimetypes.knownfiles |
class mimetypes.MimeTypes(filenames=(), strict=True)
This class represents a MIME-types database. By default, it provides access to the same database as the rest of this module. The initial database is a copy of that provided by the module, and may be extended by loading additional mime.types-style files into the dat... | python.library.mimetypes#mimetypes.MimeTypes |
encodings_map
Dictionary mapping filename extensions to encoding types. This is initially a copy of the global encodings_map defined in the module. | python.library.mimetypes#mimetypes.MimeTypes.encodings_map |
guess_all_extensions(type, strict=True)
Similar to the guess_all_extensions() function, using the tables stored as part of the object. | python.library.mimetypes#mimetypes.MimeTypes.guess_all_extensions |
guess_extension(type, strict=True)
Similar to the guess_extension() function, using the tables stored as part of the object. | python.library.mimetypes#mimetypes.MimeTypes.guess_extension |
guess_type(url, strict=True)
Similar to the guess_type() function, using the tables stored as part of the object. | python.library.mimetypes#mimetypes.MimeTypes.guess_type |
read(filename, strict=True)
Load MIME information from a file named filename. This uses readfp() to parse the file. If strict is True, information will be added to list of standard types, else to the list of non-standard types. | python.library.mimetypes#mimetypes.MimeTypes.read |
readfp(fp, strict=True)
Load MIME type information from an open file fp. The file must have the format of the standard mime.types files. If strict is True, information will be added to the list of standard types, else to the list of non-standard types. | python.library.mimetypes#mimetypes.MimeTypes.readfp |
read_windows_registry(strict=True)
Load MIME type information from the Windows registry. Availability: Windows. If strict is True, information will be added to the list of standard types, else to the list of non-standard types. New in version 3.2. | python.library.mimetypes#mimetypes.MimeTypes.read_windows_registry |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.