np.round函数各参数说明
时间: 2023-08-16 11:13:57 浏览: 173
Python中 map()函数的用法详解
np.round()函数是一个numpy库中的函数,用于对给定的数组进行四舍五入。它可以指定保留的小数位数。函数的参数如下:
- array:要进行四舍五入的数组。
- decimals:保留的小数位数,默认为0,即取整数。
示例代码如下:
```python
import numpy as np
x = \[10.7, 10.5, 10.3, 11.7, 11.5, 11.3, 0.7, 0.5, 0.3\]
y = np.round(x)
print(y)
```
输出结果为:
```
\[11. 11. 10. 12. 12. 11. 1. 0. 0.\]
```
其中,数组x中的每个元素都被四舍五入到最接近的整数。\[1\]
#### 引用[.reference_title]
- *1* [np中的round函数,ceil函数与floor函数](https://blog.csdn.net/weixin_42596275/article/details/126222136)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Python-Numpy函数:np.round(),np.around(),np.floor(),np.ceil()](https://blog.csdn.net/lss1990lss/article/details/119705204)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [Python round()函数的严谨用法](https://blog.csdn.net/u011699626/article/details/122091029)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文