# Python numpy.round_() 使用实例

The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.

Example 1

```def test_2d(self):
# Tests mr_ on 2D arrays.
a_1 = np.random.rand(5, 5)
a_2 = np.random.rand(5, 5)
m_1 = np.round_(np.random.rand(5, 5), 0)
m_2 = np.round_(np.random.rand(5, 5), 0)
# append columns
d = mr_['1', b_1, b_2]
self.assertTrue(d.shape == (5, 10))
assert_array_equal(d[:, :5], b_1)
assert_array_equal(d[:, 5:], b_2)
d = mr_[b_1, b_2]
self.assertTrue(d.shape == (10, 5))
assert_array_equal(d[:5,:], b_1)
assert_array_equal(d[5:,:], b_2)

Example 2

```def test_2d(self):
# Tests mr_ on 2D arrays.
a_1 = np.random.rand(5, 5)
a_2 = np.random.rand(5, 5)
m_1 = np.round_(np.random.rand(5, 5), 0)
m_2 = np.round_(np.random.rand(5, 5), 0)
# append columns
d = mr_['1', b_1, b_2]
self.assertTrue(d.shape == (5, 10))
assert_array_equal(d[:, :5], b_1)
assert_array_equal(d[:, 5:], b_2)
d = mr_[b_1, b_2]
self.assertTrue(d.shape == (10, 5))
assert_array_equal(d[:5,:], b_1)
assert_array_equal(d[5:,:], b_2)

Example 3

```def test_2d(self):
# Tests mr_ on 2D arrays.
a_1 = np.random.rand(5, 5)
a_2 = np.random.rand(5, 5)
m_1 = np.round_(np.random.rand(5, 5), 0)
m_2 = np.round_(np.random.rand(5, 5), 0)
# append columns
d = mr_['1', b_1, b_2]
self.assertTrue(d.shape == (5, 10))
assert_array_equal(d[:, :5], b_1)
assert_array_equal(d[:, 5:], b_2)
d = mr_[b_1, b_2]
self.assertTrue(d.shape == (10, 5))
assert_array_equal(d[:5,:], b_1)
assert_array_equal(d[5:,:], b_2)

Example 4

```def test_2d(self):
# Tests mr_ on 2D arrays.
a_1 = np.random.rand(5, 5)
a_2 = np.random.rand(5, 5)
m_1 = np.round_(np.random.rand(5, 5), 0)
m_2 = np.round_(np.random.rand(5, 5), 0)
# append columns
d = mr_['1', b_1, b_2]
self.assertTrue(d.shape == (5, 10))
assert_array_equal(d[:, :5], b_1)
assert_array_equal(d[:, 5:], b_2)
d = mr_[b_1, b_2]
self.assertTrue(d.shape == (10, 5))
assert_array_equal(d[:5,:], b_1)
assert_array_equal(d[5:,:], b_2)

Example 5

```def test_2d(self):
# Tests mr_ on 2D arrays.
a_1 = np.random.rand(5, 5)
a_2 = np.random.rand(5, 5)
m_1 = np.round_(np.random.rand(5, 5), 0)
m_2 = np.round_(np.random.rand(5, 5), 0)
# append columns
d = mr_['1', b_1, b_2]
self.assertTrue(d.shape == (5, 10))
assert_array_equal(d[:, :5], b_1)
assert_array_equal(d[:, 5:], b_2)
d = mr_[b_1, b_2]
self.assertTrue(d.shape == (10, 5))
assert_array_equal(d[:5,:], b_1)
assert_array_equal(d[5:,:], b_2)

Example 6

```def test_2d(self):
# Tests mr_ on 2D arrays.
a_1 = np.random.rand(5, 5)
a_2 = np.random.rand(5, 5)
m_1 = np.round_(np.random.rand(5, 5), 0)
m_2 = np.round_(np.random.rand(5, 5), 0)
# append columns
d = mr_['1', b_1, b_2]
self.assertTrue(d.shape == (5, 10))
assert_array_equal(d[:, :5], b_1)
assert_array_equal(d[:, 5:], b_2)
d = mr_[b_1, b_2]
self.assertTrue(d.shape == (10, 5))
assert_array_equal(d[:5,:], b_1)
assert_array_equal(d[5:,:], b_2)

Example 7

```def test_2d(self):
# Tests mr_ on 2D arrays.
a_1 = np.random.rand(5, 5)
a_2 = np.random.rand(5, 5)
m_1 = np.round_(np.random.rand(5, 5), 0)
m_2 = np.round_(np.random.rand(5, 5), 0)
# append columns
d = mr_['1', b_1, b_2]
self.assertTrue(d.shape == (5, 10))
assert_array_equal(d[:, :5], b_1)
assert_array_equal(d[:, 5:], b_2)
d = mr_[b_1, b_2]
self.assertTrue(d.shape == (10, 5))
assert_array_equal(d[:5,:], b_1)
assert_array_equal(d[5:,:], b_2)

Example 8

```def round_(a, decimals=0, out=None):
"""
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 'decimals' is greater than or equal
to 0.

Parameters
----------
decimals : int
Number of decimals to round to. May be negative.
out : array_like
Existing array to use for output.
If not given, returns a default copy of a.

Notes
-----
If out is given and does not have a mask attribute, the mask of a
is lost!

"""
if out is None:
return np.round_(a, decimals, out)
else:
np.round_(getdata(a), decimals, out)
return out ```

Example 9

```def round_(a, decimals=0, out=None):
"""
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 'decimals' is greater than or equal
to 0.

Parameters
----------
decimals : int
Number of decimals to round to. May be negative.
out : array_like
Existing array to use for output.
If not given, returns a default copy of a.

Notes
-----
If out is given and does not have a mask attribute, the mask of a
is lost!

"""
if out is None:
return np.round_(a, decimals, out)
else:
np.round_(getdata(a), decimals, out)
return out ```

Example 10

```def round_(a, decimals=0, out=None):
"""
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 'decimals' is greater than or equal
to 0.

Parameters
----------
decimals : int
Number of decimals to round to. May be negative.
out : array_like
Existing array to use for output.
If not given, returns a default copy of a.

Notes
-----
If out is given and does not have a mask attribute, the mask of a
is lost!

"""
if out is None:
return np.round_(a, decimals, out)
else:
np.round_(getdata(a), decimals, out)
return out ```

Example 11

```def round_(a, decimals=0, out=None):
"""
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 'decimals' is greater than or equal
to 0.

Parameters
----------
decimals : int
Number of decimals to round to. May be negative.
out : array_like
Existing array to use for output.
If not given, returns a default copy of a.

Notes
-----
If out is given and does not have a mask attribute, the mask of a
is lost!

"""
if out is None:
return np.round_(a, decimals, out)
else:
np.round_(getdata(a), decimals, out)
return out ```

Example 12

```def std_score(a):
return np.round_(50 + 10 * (a - np.average(a)) / np.std(a)) ```

Example 13

```def round_(a, decimals=0, out=None):
"""
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 'decimals' is greater than or equal
to 0.

Parameters
----------
decimals : int
Number of decimals to round to. May be negative.
out : array_like
Existing array to use for output.
If not given, returns a default copy of a.

Notes
-----
If out is given and does not have a mask attribute, the mask of a
is lost!

"""
if out is None:
return np.round_(a, decimals, out)
else:
np.round_(getdata(a), decimals, out)
return out ```

Example 14

```def test_round(self):
param_str = "round(2.45, 1) -> float"
test_param = TemplateParameter(parameter_str=param_str, type_converter=self.type_converter)
result = test_param.render(df=test_df)
self.assertEquals(result, np.round_(2.45, 1)) ```

Example 15

```def _execute(self, value, decimals):
return np.round_(value, decimals) ```

Example 16

```def _execute(self, value, decimals):
return np.round_(value, decimals) ```

Example 17

```def _execute(self, value, decimals):
return np.round_(value, decimals) ```

Example 18

```def round_(a, decimals=0, out=None):
"""
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 'decimals' is greater than or equal
to 0.

Parameters
----------
decimals : int
Number of decimals to round to. May be negative.
out : array_like
Existing array to use for output.
If not given, returns a default copy of a.

Notes
-----
If out is given and does not have a mask attribute, the mask of a
is lost!

"""
if out is None:
return np.round_(a, decimals, out)
else:
np.round_(getdata(a), decimals, out)
return out ```

Example 19

```def round_(a, decimals=0, out=None):
"""
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 'decimals' is greater than or equal
to 0.

Parameters
----------
decimals : int
Number of decimals to round to. May be negative.
out : array_like
Existing array to use for output.
If not given, returns a default copy of a.

Notes
-----
If out is given and does not have a mask attribute, the mask of a
is lost!

"""
if out is None:
return np.round_(a, decimals, out)
else:
np.round_(getdata(a), decimals, out)
return out ```

Example 20

```def _calculate_score(solution, prediction, task_type, metric=None):

solution = np.array(solution, dtype=np.float32)

# This used to crash on travis-ci; special treatment to find out why
# it crashed!
solution_binary = np.zeros(prediction.shape)

for i in range(solution_binary.shape[0]):
label = int(np.round_(solution[i]))
solution_binary[i, label] = 1
solution = solution_binary

solution = solution.reshape(-1, 1)
prediction = prediction[:, 1].reshape(-1, 1)

if solution.shape != prediction.shape:
raise ValueError("Solution shape %s != prediction shape %s" %
(solution.shape, prediction.shape))

if metric is None:
score = dict()
cprediction = sanitize_array(prediction)
for metric_ in REGRESSION_METRICS:
score[metric_] = regression_metrics.calculate_score(metric_,
solution,
cprediction)
else:
csolution, cprediction = normalize_array(solution, prediction)
for metric_ in CLASSIFICATION_METRICS:
score[metric_] = classification_metrics.calculate_score(

for metric_ in score:
if np.isnan(score[metric_]):
score[metric_] = 0

else:
cprediction = sanitize_array(prediction)
score = regression_metrics.calculate_score(metric,
solution,
cprediction)
else:
csolution, cprediction = normalize_array(solution, prediction)
score = classification_metrics.calculate_score(metric,
csolution,
cprediction,