Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.around

numpy.around(a,decimals=0,out=None)[source]

Evenly round to the given number of decimals.

Parameters:
a:array_like

Input data.

decimals:int, optional

Number of decimal places to round to (default: 0). Ifdecimals is negative, it specifies the number of positions tothe left of the decimal point.

out:ndarray, optional

Alternative output array in which to place the result. It must havethe same shape as the expected output, but the type of the outputvalues will be cast if necessary. Seedoc.ufuncs (Section“Output arguments”) for details.

Returns:
rounded_array:ndarray

An array of the same type asa, containing the rounded values.Unlessout was specified, a new array is created. A reference tothe result is returned.

The real and imaginary parts of complex numbers are roundedseparately. The result of rounding a float is a float.

See also

ndarray.round
equivalent method

ceil,fix,floor,rint,trunc

Notes

For values exactly halfway between rounded decimal values, NumPyrounds to the nearest even value. Thus 1.5 and 2.5 round to 2.0,-0.5 and 0.5 round to 0.0, etc. Results may also be surprising dueto the inexact representation of decimal fractions in the IEEEfloating point standard[1] and errors introduced when scalingby powers of ten.

References

[1](1,2) “Lecture Notes on the Status of IEEE 754”, William Kahan,http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF
[2]“How Futile are Mindless Assessments ofRoundoff in Floating-Point Computation?”, William Kahan,http://www.cs.berkeley.edu/~wkahan/Mindless.pdf

Examples

>>>np.around([0.37,1.64])array([ 0.,  2.])>>>np.around([0.37,1.64],decimals=1)array([ 0.4,  1.6])>>>np.around([.5,1.5,2.5,3.5,4.5])# rounds to nearest even valuearray([ 0.,  2.,  2.,  4.,  4.])>>>np.around([1,2,3,11],decimals=1)# ndarray of ints is returnedarray([ 1,  2,  3, 11])>>>np.around([1,2,3,11],decimals=-1)array([ 0,  0,  0, 10])

Previous topic

numpy.arctanh

Next topic

numpy.round_

Quick search

  • © Copyright 2008-2018, The SciPy community.
  • Last updated on Jul 24, 2018.
  • Created usingSphinx 1.6.6.

[8]ページ先頭

©2009-2025 Movatter.jp