python sklearn 数据预处理 归一化
"""
数据预处理 归一化
"""
import numpy as np
import sklearn.preprocessing as sp
# 准备数据
ary = np.array([
[10, 21, 5],
[2, 4, 1],
[11, 18, 18]
])
# 归一化 行方向
normal_ary = sp.normalize(ary, norm="l1", axis=1)
print(normal_ary)
python sklearn 数据预处理 二值化
文件下载地址:
链接: https://pan.baidu.com/s/1IpA7DSCCdcTy2N2wxbaIKw 提取码: ujn5
"""
数据预处理 二值化
"""
import cv2
import matplotlib.pyplot as mp
import numpy as np
import sklearn.preprocessing as sp
# 准备数据
ary = np.array([
[10, 21, 5],
[2, 4, 1],
[11, 18, 18]
])
# 二值化 数据
bin = sp.Binarizer(threshold=10)
result = bin.transform(ary)
print(result)
# 二值化图片
lily = cv2.imread("./lily.jpg", cv2.IMREAD_GRAYSCALE)
bin_img = sp.Binarizer(threshold=127)
result = bin_img.transform(lily)
mp.imshow(result, cmap="gray")
mp.show()