Python
小松萘
厉害的人可真多啊
展开
-
Python将字符串解析为类名
class dog: def __init__(self): self.name = "hello" def fun(self): print(eval("self.name"))tmp = dog()tmp.fun()原创 2020-11-15 11:39:05 · 873 阅读 · 0 评论 -
解决python父线程关闭后子线程不关闭问题
import threadingtimer = threading.Timer(0.2, self.fun_timer)timer.setDaemon(True) # !!timer.start()原创 2020-11-13 21:59:21 · 693 阅读 · 0 评论 -
python使用threading.Timer实现线程循环任务定时器
def fun_timer(self): globals.T += 1 print(globals.T) global timer timer = threading.Timer(0.2, self.fun_timer) timer.start() def on_pushButton_clicked(self): timer = threading.Timer(0.2, self.fun_timer...原创 2020-11-12 22:57:22 · 564 阅读 · 0 评论 -
Python 中的Socket编程
文章目录Python 中的Socket编程一、数据传输方式1.1 同步与异步1.2 阻塞非阻塞1.3 IO模型1.3.1 同步阻塞1.3.2 同步非阻塞1.3.3 IO多路复用1.3.4 异步1.3.5 对比二、Socket API三、实验代码3.1 同步阻塞3.1.1 服务端3.1.2 客户端3.1.3 测试3.2 非阻塞3.2.1 服务端3.2.2 用户端3.2.3 测试3.3 多路复用IO3.3.1 服务端3.3.2 客户端3.3.3 测试3.4 异步3.4.1 服务端与客户端3.4.2 测试3.5原创 2020-10-27 00:39:17 · 466 阅读 · 1 评论 -
KD 树 K个查找 python实现
import heapqimport numpy as npfrom sklearn.preprocessing import StandardScalerclass Node(): # KD 树节点 def __init__(self): self.father = None self.left = None self.right = None self.feature = None self.spli原创 2020-10-08 17:22:19 · 177 阅读 · 0 评论 -
Python 学习中遇到的
python map()函数和lambda表达式(匿名函数)QAQ原创 2020-10-07 17:23:56 · 72 阅读 · 0 评论 -
Python PIL.Image一些应用
from PIL import Imagedef addTransparency(img, factor=0.7): img = img.convert('RGBA') img_blender = Image.new('RGBA', img.size, (0, 0, 0, 0)) img = Image.blend(img_blender, img, factor) return imgimg = Image.open("./assets/back12.jpg "原创 2020-08-27 18:38:34 · 301 阅读 · 0 评论 -
Python读取 csv 文件出现‘gbk‘ codec can‘t decode byte 0xbf in position 2 解决方法
Excel 另存文件时,选择然后读取import numpy as np data = np.loadtxt('data.csv', dtype=int, delimiter=',')print(data)原创 2020-07-15 11:39:56 · 1864 阅读 · 0 评论 -
Python - 常用预处理方法
import numpy as npfrom sklearn.linear_model import LinearRegressionimport pandas as pdimport pywtimport matplotlib.pyplot as pltdef snv(data_x): #标准正态变换 m = data_x.shape[0] n = data_x.shape[1] data_std = np.std(data_x, axis=1) data_a原创 2020-11-01 17:43:21 · 612 阅读 · 0 评论 -
Python - 最小偏二乘法PLS代码
# -*-coding:GBK -*-import mathimport numpy as npfrom sklearn import svmfrom sklearn import preprocessingfrom sklearn import model_selectionfrom sklearn.impute import SimpleImputerfrom sklearn.metrics import accuracy_scorefrom sklearn.model_selectio原创 2020-07-10 08:45:54 · 2216 阅读 · 1 评论 -
Python -机器学习 -svm.SVC分类
svm.SVC参数文档sklearn.svm.SVC(C=1.0, kernel='rbf', degree=3, gamma='auto', coef0=0.0, shrinking=True, probability=False, tol=0.001, cache_size=200, class_weight=None, verbose=False, max_iter=-1, decision_function_shape=None,random_state=None)C:float类型,默原创 2020-06-24 13:28:38 · 4576 阅读 · 1 评论 -
Python - 杂七杂八
1,中文乱码问题官方解释文档python 默认是使用 ascii 编码的,直接 print(“中文”) 是会报错的,eg:print("你好")需要在代码第一行加上以下任一种指定编码#coding = utf-8#coding : utf-8# -*- coding: utf-8 -*-# -*- coding= utf-8 -*-...原创 2020-06-23 08:39:29 · 138 阅读 · 0 评论 -
Python - 类
(1)init为类的构造函数,可以在里面实例化实例变量(2)每个类函数比普通函数多一个self变量,代表当前实例对象class IN: def __init__(self): self.a = 1 self.b = 2 def printf(self): print(self.a,self.b)x = IN();x.printf();...原创 2020-06-06 23:07:45 · 113 阅读 · 0 评论