The bool type is not a subclass of the int_ type
(the bool is not even a number type). This is different
than Python’s default implementation of bool as a
sub-class of int.
The bool type is not a subclass of the int_ type
(the bool is not even a number type). This is different
than Python’s default implementation of bool as a
sub-class of int.
Return the binary representation of the input number as a string.
For negative numbers, if width is not given, a minus sign is added to the
front. If width is given, the two’s complement of the number is
returned, with respect to that width.
In a two’s-complement system negative numbers are represented by the two’s
complement of the absolute value. This is the most common method of
representing signed integers on computers [1]_. A N-bit two’s-complement
system can represent every integer in the range
\(-2^{N-1}\) to \(+2^{N-1}-1\).
Parameters:
num (int) – Only an integer decimal number can be used.
width (int, optional) – The length of the returned string if num is positive, or the length
of the two’s complement if num is negative, provided that width is
at least a sufficient number of bits for num to be represented in
the designated form. If the width value is insufficient, an error is
raised.
Returns:
bin – Binary representation of num or two’s complement of num.
If created from a 64-bit integer, it represents an offset from 1970-01-01T00:00:00.
If created from string, the string can be in ISO 8601 date or datetime format.
When parsing a string to create a datetime object, if the string contains
a trailing timezone (A ‘Z’ or a timezone offset), the timezone will be
dropped and a User Warning is given.
Datetime64 objects should be considered to be UTC and therefore have an
offset of +0000.
Return a pair of integers, whose ratio is exactly equal to the original
floating point number, and with a positive denominator.
Raise OverflowError on infinities and a ValueError on NaNs.
Returns the dtype for which finfo returns information. For complex
input, the returned dtype is the associated float* dtype for its
real and complex components.
The difference between 1.0 and the next smallest representable float
larger than 1.0. For example, for 64-bit binary floats in the IEEE-754
standard, eps=2**-52, approximately 2.22e-16.
The difference between 1.0 and the next smallest representable float
less than 1.0. For example, for 64-bit binary floats in the IEEE-754
standard, epsneg=2**-53, approximately 1.11e-16.
The distance between a value and the nearest adjacent number
nextafter
The next floating point value after x1 towards x2
Notes
For developers of NumPy: do not instantiate this at the module level.
The initial calculation of these parameters is expensive and negatively
impacts import times. These objects are cached, so calling finfo()
repeatedly inside your functions is not a problem.
Note that smallest_normal is not actually the smallest positive
representable value in a NumPy floating point type. As in the IEEE-754
standard [1]_, NumPy floating point types make use of subnormal numbers to
fill the gap between 0 and smallest_normal. However, subnormal numbers
may have significantly reduced precision [2].
For longdouble, the representation varies across platforms. On most
platforms it is IEEE 754 binary128 (quad precision) or binary64-extended
(80-bit extended precision). On PowerPC systems, it may use the IBM
double-double format (a pair of float64 values), which has special
characteristics for precision and range.
This function can also be used for complex data types as well. If used,
the output will be the same as the corresponding real float type
(e.g. numpy.finfo(numpy.csingle) is the same as numpy.finfo(numpy.single)).
However, the output is true for the real and imaginary components.
Format a floating-point scalar as a decimal string in positional notation.
Provides control over rounding, trimming and padding. Uses and assumes
IEEE unbiased rounding. Uses the “Dragon4” algorithm.
Parameters:
x (python float or numpy floating scalar) – Value to format.
precision (non-negative integer or None, optional) – Maximum number of digits to print. May be None if unique is
True, but must be an integer if unique is False.
unique (boolean, optional) – If True, use a digit-generation strategy which gives the shortest
representation which uniquely identifies the floating-point number from
other values of the same type, by judicious rounding. If precision
is given fewer digits than necessary can be printed, or if min_digits
is given more can be printed, in which cases the last digit is rounded
with unbiased rounding.
If False, digits are generated as if printing an infinite-precision
value and stopping after precision digits, rounding the remaining
value with unbiased rounding
fractional (boolean, optional) – If True, the cutoffs of precision and min_digits refer to the
total number of digits after the decimal point, including leading
zeros.
If False, precision and min_digits refer to the total number of
significant digits, before or after the decimal point, ignoring leading
zeros.
trim (one of 'k', '.', '0', '-', optional) –
Controls post-processing trimming of trailing digits, as follows:
’k’ : keep trailing zeros, keep decimal point (no trimming)
’.’ : trim all trailing zeros, leave decimal point
’0’ : trim all but the zero before the decimal point. Insert the
zero if it is missing.
’-’ : trim trailing zeros and any trailing decimal point
sign (boolean, optional) – Whether to show the sign for positive values.
pad_left (non-negative integer, optional) – Pad the left side of the string with whitespace until at least that
many characters are to the left of the decimal point.
pad_right (non-negative integer, optional) – Pad the right side of the string with whitespace until at least that
many characters are to the right of the decimal point.
min_digits (non-negative integer or None, optional) –
Minimum number of digits to print. Only has an effect if unique=True
in which case additional digits past those necessary to uniquely
identify the value may be printed, rounding the last additional digit.
Added in version 1.21.0.
Returns:
rep – The string representation of the floating point value
Format a floating-point scalar as a decimal string in scientific notation.
Provides control over rounding, trimming and padding. Uses and assumes
IEEE unbiased rounding. Uses the “Dragon4” algorithm.
Parameters:
x (python float or numpy floating scalar) – Value to format.
precision (non-negative integer or None, optional) – Maximum number of digits to print. May be None if unique is
True, but must be an integer if unique is False.
unique (boolean, optional) – If True, use a digit-generation strategy which gives the shortest
representation which uniquely identifies the floating-point number from
other values of the same type, by judicious rounding. If precision
is given fewer digits than necessary can be printed. If min_digits
is given more can be printed, in which cases the last digit is rounded
with unbiased rounding.
If False, digits are generated as if printing an infinite-precision
value and stopping after precision digits, rounding the remaining
value with unbiased rounding
trim (one of 'k', '.', '0', '-', optional) –
Controls post-processing trimming of trailing digits, as follows:
’k’ : keep trailing zeros, keep decimal point (no trimming)
’.’ : trim all trailing zeros, leave decimal point
’0’ : trim all but the zero before the decimal point. Insert the
zero if it is missing.
’-’ : trim trailing zeros and any trailing decimal point
sign (boolean, optional) – Whether to show the sign for positive values.
pad_left (non-negative integer, optional) – Pad the left side of the string with whitespace until at least that
many characters are to the left of the decimal point.
exp_digits (non-negative integer, optional) – Pad the exponent with zeros until it contains at least this
many digits. If omitted, the exponent will be at least 2 digits.
min_digits (non-negative integer or None, optional) –
Minimum number of digits to print. This only has an effect for
unique=True. In that case more digits than necessary to uniquely
identify the value may be printed and rounded unbiased.
Added in version 1.21.0.
Returns:
rep – The string representation of the floating point value
Return a pair of integers, whose ratio is exactly equal to the original
floating point number, and with a positive denominator.
Raise OverflowError on infinities and a ValueError on NaNs.
Abstract base class of all numeric scalar types with a (potentially)
inexact representation of the values in its range, such as
floating-point numbers.
If you need a stricter way to identify a numerical scalar, use
isinstance(x,numbers.Number), as that returns False for most
non-numerical elements such as strings.
In most cases np.ndim(x)==0 should be used instead of this function,
as that will also return true for 0d arrays. This is how numpy overloads
functions in the style of the dx arguments to gradient and
the bins argument to histogram. Some key differences:
x
isscalar(x)
np.ndim(x)==0
PEP 3141 numeric objects
(including builtins)
True
True
builtin string and buffer objects
True
True
other builtin objects, like
pathlib.Path, Exception,
the result of re.compile
Return a pair of integers, whose ratio is exactly equal to the original
floating point number, and with a positive denominator.
Raise OverflowError on infinities and a ValueError on NaNs.
D.update([E, ]**F) -> None. Update D from mapping/iterable E and F.
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k]
If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v
In either case, this is followed by: for k in F: D[k] = F[k]
Return a pair of integers, whose ratio is exactly equal to the original
floating point number, and with a positive denominator.
Raise OverflowError on infinities and a ValueError on NaNs.
Create a new structured or unstructured void scalar.
Parameters:
length_or_data (int, array-like, bytes-like, object) – One of multiple meanings (see notes). The length or
bytes data of an unstructured void. Or alternatively,
the data to be stored in the new scalar when dtype
is provided.
This can be an array-like, in which case an array may
be returned.
If provided the dtype of the new scalar. This dtype must
be “void” dtype (i.e. a structured or unstructured void,
see also defining-structured-types).
Added in version 1.24.
Notes
For historical reasons and because void scalars can represent both
arbitrary byte data and structured dtypes, the void constructor
has three calling conventions:
np.void(5) creates a dtype="V5" scalar filled with five
\0 bytes. The 5 can be a Python or NumPy integer.
np.void(b"bytes-like") creates a void scalar from the byte string.
The dtype itemsize will match the byte string length, here "V10".
When a dtype= is passed the call is roughly the same as an
array creation. However, a void scalar rather than array is returned.
Please see the examples which show all three different conventions.