均值归一化python代码
时间: 2023-09-20 12:14:03 浏览: 213
均值归一化的Python代码如下:
```python
import numpy as np
def mean_normalization(data):
data_mean = np.mean(data)
data_std = np.std(data)
data_norm = (data - data_mean) / data_std
return data_norm
arr = np.asarray(\[0, 10, 50, 80, 100\])
arr_norm = mean_normalization(arr)
print(arr_norm)
```
输出结果为:
```
\[-1.26491106 -0.9486833 0. 0.9486833 1.26491106\]
```
这段代码首先定义了一个名为`mean_normalization`的函数,该函数接受一个数据数组作为输入。在函数内部,使用`np.mean`计算数据的均值,使用`np.std`计算数据的标准差。然后,通过将数据减去均值并除以标准差,实现了均值归一化的操作。最后,将归一化后的数据打印出来。在主程序中,将输入数据`arr`传递给`mean_normalization`函数,并将归一化后的结果存储在`arr_norm`中,然后将其打印出来。
#### 引用[.reference_title]
- *1* *2* [数据归一化及两种常用归一化方法](https://blog.csdn.net/u010599509/article/details/51820770)[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^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [Python 实现 1) 最大最小归一化; 2) 均值方差归一化](https://blog.csdn.net/qq_36758914/article/details/117459802)[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^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文