Return a copy of a, rounded to 'decimals' places. When 'decimals' is negative, it specifies the number of positions to the left of the decimal point. The real and imaginary parts of complex numbers are rounded separately. Nothing is done if the array is not of float type and '
(a, decimals=0, out=None)
| 8096 | |
| 8097 | |
| 8098 | def round(a, decimals=0, out=None): |
| 8099 | """ |
| 8100 | Return a copy of a, rounded to 'decimals' places. |
| 8101 | |
| 8102 | When 'decimals' is negative, it specifies the number of positions |
| 8103 | to the left of the decimal point. The real and imaginary parts of |
| 8104 | complex numbers are rounded separately. Nothing is done if the |
| 8105 | array is not of float type and 'decimals' is greater than or equal |
| 8106 | to 0. |
| 8107 | |
| 8108 | Parameters |
| 8109 | ---------- |
| 8110 | decimals : int |
| 8111 | Number of decimals to round to. May be negative. |
| 8112 | out : array_like |
| 8113 | Existing array to use for output. |
| 8114 | If not given, returns a default copy of a. |
| 8115 | |
| 8116 | Notes |
| 8117 | ----- |
| 8118 | If out is given and does not have a mask attribute, the mask of a |
| 8119 | is lost! |
| 8120 | |
| 8121 | Examples |
| 8122 | -------- |
| 8123 | >>> import numpy as np |
| 8124 | >>> import numpy.ma as ma |
| 8125 | >>> x = [11.2, -3.973, 0.801, -1.41] |
| 8126 | >>> mask = [0, 0, 0, 1] |
| 8127 | >>> masked_x = ma.masked_array(x, mask) |
| 8128 | >>> masked_x |
| 8129 | masked_array(data=[11.2, -3.973, 0.801, --], |
| 8130 | mask=[False, False, False, True], |
| 8131 | fill_value=1e+20) |
| 8132 | >>> ma.round(masked_x) |
| 8133 | masked_array(data=[11.0, -4.0, 1.0, --], |
| 8134 | mask=[False, False, False, True], |
| 8135 | fill_value=1e+20) |
| 8136 | >>> ma.round(masked_x, decimals=1) |
| 8137 | masked_array(data=[11.2, -4.0, 0.8, --], |
| 8138 | mask=[False, False, False, True], |
| 8139 | fill_value=1e+20) |
| 8140 | >>> ma.round(masked_x, decimals=-1) |
| 8141 | masked_array(data=[10.0, -0.0, 0.0, --], |
| 8142 | mask=[False, False, False, True], |
| 8143 | fill_value=1e+20) |
| 8144 | """ |
| 8145 | if out is None: |
| 8146 | return np.round(a, decimals, out) |
| 8147 | else: |
| 8148 | np.round(getdata(a), decimals, out) |
| 8149 | if hasattr(out, '_mask'): |
| 8150 | out._mask = getmask(a) |
| 8151 | return out |
| 8152 | |
| 8153 | |
| 8154 | def round_(a, decimals=0, out=None): |
searching dependent graphs…