- 博客(65)
- 收藏
- 关注

原创 numpy.random 模块中文文档学习笔记
1 numpy.random.randint()整数随机,指定上下界,左闭右开np.random.randint(1, size=10)>>> array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])np.random.randint(2, size=10)>>> array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0])np.random.randint(5, size=(2, 4))>>> arra
2020-10-20 14:00:48
604
1

原创 【Python】打开/查看 pkl csv json txt 文件
import picklef = open('your_file_name.pkl','rb')info = pickle.load(f)print(info)
2020-10-15 21:47:51
1250
原创 【特征工程】数据缺失值处理
1 不进行处理在数据源包含nan之类的值的时候也能进行建模:lightGBM(把缺失值看作一类,本质上也是真值转换,不推荐)Cart树(为了提升预测效果而填充,容易过拟合,不推荐)一般还是要处理缺失值。2 简单处理真值转换:把年龄、学号等属性给自动填充为固定的值,例如将部分缺失年龄的数据填充为-1。此外,也可以通过从业务逻辑溯源的方法进行缺失值的找回。暴力删除:直接删除带nan的数据(缺失比例较小)。3 处理方法3.1 统计量插补均值、众数、中位数、特殊值(样本前/后的一个值)
2022-01-31 03:38:24
3777
原创 matplotlib快速画图
range_ = 1.5compare_line = list(np.arange(-range_,range_,0.01))font_size = 16plt.rcParams['font.family'] = 'SimHei'plt.rcParams['font.size'] = font_sizeplt.rcParams['axes.unicode_minus'] = False# 测试集plt.figure(figsize=(8,6))plt.scatter(pred_te
2022-01-11 15:40:35
440
原创 webots python e-puck 集群通信案例
导入模块from controller import Robot, Supervisor, Receiver, Emitter实例化e-puck机器人对象,开启传感器,设定参数# 初始化e-puck机器人模块spvr = Supervisor()robot_name = "e-puck_666"robot_spr = spvr.getFromDef(robot_name)timestep = int(spvr.getBasicTimeStep()) # 时间粒度默认为32毫秒its_na
2021-11-03 00:06:16
781
原创 ERROR: Could not find a version that satisfies the requirement absl (from versions: none) ERROR: No
pip install absl安装absl库时遇到问题ERROR: Could not find a version that satisfies the requirement absl (from versions: none)ERROR: No matching distribution found for absl应该改为pip install absl-py
2021-11-02 15:16:48
2452
2
原创 plotplayer s/w hevc(h265)解码 问题
前往:下载地址找到:下载:LAVFilters-0.75.1-Installer.exe安装,即可解决问题
2021-10-12 16:54:41
1406
1
原创 【Python】排序函数 sort、sorted 对复杂列表排序
1 lambda 表达式匿名函数。匿名函数lambda:是指一类无需定义标识符(函数名)的函数或子程序。lambda 函数可以接收任意多个参数 (包括可选参数) 并且返回单个表达式的值。lambda 函数不能包含命令。包含的表达式不能超过一个。a = lambda x,y,z:(x+8)*y-zprint(a(5,6,8))>> 702 sorted() 方法默认升序排列a = [5,7,6,3,4,1,2]b = sorted(a) # 保留原列表a
2021-08-19 00:03:19
653
原创 【Python】常用字符串api
1 strip()方法去除字符串中指定的字符s = "123abc "s.strip(" ") # 去除空格s = "123abc"2 replace()方法替换指定字符为其他字符s = "123abc "s.replace(" ","1") # 将空格替换为1s = "123abc111"去除 回车\r 和 换行符\ns.replace('\n', '').replace('\r', '')3 大小写转换str = "www.runoob.com"print(
2021-08-18 23:18:26
410
原创 机器学习面试题目整理
1 归一化1.1 定义将数据映射到指定的范围,如:把数据映射到0~1或-1~1的范围之内处理。1.2 常见做法min-max 归一化,也叫 0-1 标准化1.3 作用有量纲表达式变成无量纲表达式,便于不同单位或量级的指标能够进行比较和加权简化计算数据映射到指定的范围内进行处理,更加便捷快速2 标准化2.1 定义将数据变换为均值为0,标准差为1的分布,切记,并非一定是正态的2.2 通常做法z-score 标准化robust 标准化(RobustScaler)MaxAbs
2021-08-17 21:44:15
581
原创 【Python】int binary str 互转
1 int() 用法int() 是 python 内置的对象转 int 的方法# str 进行十进制转换int('10',10)>> 10int('2',10)>> 2# str 进行二进制转换int('10',2)>> 2# str 进行其他进制转换int('101',15)>> 226int('101',16)>> 2572 int -> binx,y,z = 10,20,30bin_lst = [bi
2021-07-07 17:44:41
1305
原创 强化学习算法面试问题 & 解答
1 调参技巧2 平时训练有遇到梯度裁剪嘛3 怎么处理稀疏奖励4 PPO算法的原理5 区分on-policy和off-policy6 是否了解A3C,IMPALA等强化学习训练框架7 怎样判断训练得到的policy是最优policy8 如何降低方差...
2021-07-02 23:15:11
468
3
转载 搜索资源目录
转载bilibili:https://www.bilibili.com/video/BV1TN411d7FL?spm_id_from=333.851.b_62696c695f7265706f72745f74656368.3一、资源导航网站1、书享家(电子书资源网站导航):http://shuxiangjia.cn/2、学吧导航(自学资源网站导航):https://www.xue8nav.com/3、科塔学术(学术资源网站导航):https://site.sciping.com/4、HiPPTer(
2021-06-19 03:45:49
305
原创 c++ 读取写入txt
1 写入 ofstream out("../write.txt"); out << "["; for (int i=0; i<10; i++){ out << i; if (i != 9){ out << ","; } } out << "]"; out.close();写入的文件2 读取读取刚刚写入的txt文件ifstream in;in.open("../write.txt")
2021-05-16 00:32:12
1690
原创 c++ time.h 用法
1 时间戳#include <time.h>time_t first, second;first=time(NULL); // 当前时间时间戳Sleep(2000);second=time(NULL); // 当前时间时间戳
2021-05-15 19:17:11
1269
原创 pyinstaller 用法
1 安装pip install pyinstaller2 打包pyinstaller main.py参数详解-F 同时打包库文件-w 不创建控制台窗口,也不分配标准输入/输出-D 产生一个目录用于部署 (默认)
2021-05-13 15:09:48
174
原创 Python OS使用
import osimport timefile='/Volumes/Leopard/Users/Caroline/Desktop/1.mp4'os.path.getatime(file) #输出最近访问时间1318921018.0os.path.getctime(file) #输出文件创建时间os.path.getmtime(file) #输出最近修改时间time.gmtime(os.path.getmtime(file)) #以struct_time形式输出最近修改时间os
2021-05-09 11:52:37
99
原创 python any all
>>> a = [True, True]>>> b = [True, False]>>> c = [False, False]>>> any(a)True>>> any(b)True>>> any(c)False>>> all(a)True>>> all(b)False>>> all(c)False
2021-05-07 16:31:39
87
原创 python 求点到线段距离
1 点和线段的参数# pointp = [0,0]# line segment# point-1a = [-1,1]# point-2b = [1,1]2 求取距离import numpy as npdef dis_point_to_seg_line(p, a, b): a, b, p = np.array(a), np.array(b), np.array(p) # trans to np.array d = np.divide(b - a, np.linalg.
2021-05-06 20:17:42
2716
2
原创 python 射线法 判断点是否在 多边形内
def judgeIfInPolygon(polySides, polyX, polyY, point): in_bool = False j = polySides-1 for i in range(polySides): if ((((polyY[i]<point[1])and(polyY[j]>=point[1]))or((polyY[j]<point[1])and(polyY[i]>=point[1]))) \
2021-04-28 16:15:43
501
原创 python time datetime 使用
1 导入import datetime, time2 查看当前时间datetime.datetime.now()>> datetime.datetime(2021, 4, 20, 11, 16, 40, 342361) # 2021-4-20 11:16:40.3423613 自定义时间a = datetime.datetime(2020,1,1)>> datetime.datetime(2020, 1, 1, 0, 0) # 2020-1-1 0:0:0.0
2021-04-20 13:38:31
160
原创 ImportError: Can‘t find framework /System/Library/Frameworks/OpenGL.framework.ImportError:Error occu
pip install pyglet==1.5.11
2021-04-02 15:45:44
947
原创 python 列表生成式 字典生成式
a=["agent_{}".format(i) for i in range(10)]b={"agent_{}".format(i):i for i in range(10)}
2021-03-19 13:04:35
109
原创 python 秒数转化为时分秒
def timeCost(self, t_start): t_now = time.time() m, s = divmod(t_now-t_start, 60) h, m = divmod(m, 60) return "%02d:%02d:%02d" % (h, m, s)
2021-03-06 15:38:09
4434
原创 fatal: unable to access ‘https://github.com/xxx/‘: Failed to connect to 127.0.0.1 port 7890: Connect
git clone 项目的时候遇到报错:fatal: unable to access 'https://github.com/xxx/': Failed to connect to 127.0.0.1 port 7890: Connect解决方案:unset no_proxy;unset https_proxy
2021-03-03 11:29:17
1396
1
原创 WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connec
安装 pip 包报错(例如,安装pettingzoo包)WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection
2021-03-02 13:56:00
2279
4
原创 numpy 向量旋转任意角度
举例:向量a顺时针旋转-90度,即逆时针旋转90度:import numpy as npfrom numpy.linalg import norma = np.array([0.0, 1.0])alpha = -0.5*np.pix_ = a[1]*np.sin(alpha)+a[0]*np.cos(alpha)y_ = a[1]*np.cos(alpha)-a[0]*np.sin(alpha)print("[ {} , {} ]".format(x_, y_))结果:[ -1.0 ,
2021-02-01 22:53:26
5272
原创 numpy 求向量夹角 区间 [-pi, +pi]
求取 numpy 向量夹角可以使用 numpy.arctan2 函数;从而避免了特殊值带来的角度错误;实例:# 初始化向量a = np.array([-1.0, 1.0])b = np.array([0.0, 1.0])# 单位化(可以不用这一步)a /= norm(a)b /= norm(b)# 夹角cos值cos_ = np.dot(a,b)/(norm(a)*norm(b))# 夹角sin值sin_ = np.cross(a,b)/(norm(a)*norm(b))arcta
2021-02-01 22:07:39
7626
3
原创 AttributeError: Can‘t get attribute ‘Net‘ on module ‘__main__‘
在使用pytorch深度学习框架的时候,我们加载预先训练好的完整pkl模型时,如果报错:AttributeError: Can't get attribute 'Net' on module '__main__'此时我们应该在主函数内加载一个当时训练时的类,用于初始化神经网络,如下:# 加入:初始化class Net(nn.Module): def __init__(self, hidden_layers=64): super(Net, self).__init__()
2021-01-18 15:12:10
6585
3
原创 使用argparse对python脚本时运行时添加参数
import argparsedef parse_args(): parser = argparse.ArgumentParser("paras") now = time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime()) parser.add_argument("--now", type=str, default=now, help="current time") return parser.parse_args()argli
2021-01-14 21:17:15
553
原创 成功解决Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/xx/: There was a problem confirming
pip安装xxx库出现问题:比如,xxx是pandas(py37) user@node01:~$ pip install pandasLooking in indexes: https://pypi.tuna.tsinghua.edu.cn/simpleWARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(
2020-12-23 17:51:28
10891
4
原创 【Pygame】在 Pygame 屏幕中添加文字
font = pygame.font.SysFont("freesansbold.ttf", 30) # 30:font sizetext = font.render("content", True, (0,0,0)) # (0,0,0) color of fontself.window.blit(text,(10,10)) # (10,10) rect left top
2020-12-18 20:18:12
4990
2
原创 Windows下 Anaconda + VScode Python 环境搭建 多图 非常详细
如何在 windows 系统下搭建属于自己的 python 深度学习环境;建议收藏;1 下载 Anaconda 和 Vscode演示电脑是 64 位操作系统;Anaconda 官网下载;链接 https://www.anaconda.com/products/individualVscode 官网下载;链接 https://code.visualstudio.com/2 安装 Anaconda 和 VScode找到我们下载的目录,分别运行;注意勾选以下;在安装 VScode 时;
2020-12-10 12:44:00
3242
1
原创 【Python】彩色图片转为灰度图(4行脚本搞定)
1 安装PIL库pip install pillow2 建立文件夹建立包括彩色图片和准备保存为灰度图的文件夹;我们建立了名为 change_fig 的文件夹;fig1.jpg是我们的彩图原图;fig2.jpg是我们即将生成的灰度图;trans.py是我们的脚本;3 脚本内容from PIL import ImageI = Image.open('./fig1.jpg')L = I.convert('L')L.save("./fig2.jpg") # 灰度图fig2.jpg保存在当
2020-12-04 15:45:47
3248
3
原创 【Pygame】屏幕图形绘制
Pygame 是 python 的一个好用的仿真库;很多研究生用这个库来构建自己的实验环境;# 导入必要的库import pygame, os, sysfrom pygame.locals import *# 帧率fps = 12# 颜色WHITE = (255,255,255)BLACK = ( 0, 0, 0)RED = (255, 0, 0)GREEN
2020-12-01 19:02:29
283
原创 【Python】读取 txt 文件
使用 python 脚本对 txt 文件进行读取:使用 with 方法读取文件时,可以不用在读取后再 close 文件;本例中,txt 内容为 1,1,1;with open('./task.txt') as f: lst = f.read()print(lst)print(type(lst))# 1,1,1# <class 'str'># 默认将 txt 内容作为字符串读取lst = eval(lst)print(lst)print(type(lst))
2020-11-30 14:58:00
345
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人