python
彩云的笔记
一起编程去!!
展开
-
pygame 文本 字体
【代码】pygame 文本 字体。原创 2023-02-21 17:00:58 · 168 阅读 · 0 评论 -
pytorch torch
/home/r/Pictures/Screenshot from 2023-01-13 10-24-53.png原创 2023-01-13 11:37:21 · 102 阅读 · 0 评论 -
pytorch OutOfMemoryError
before:after:ok....看到这个提示,表示您的GPU内存不足。由于我们经常在PyTorch中处理大量数据,因此很小的错误可能会迅速导致程序耗尽所有GPU;好的事,这些情况下的修复通常很简单。原创 2023-01-11 09:55:54 · 788 阅读 · 0 评论 -
ubuntu 18.04 Pytorch安装GPU版本
之前也配置过,但是时间流逝,之前的方法也过时了(旧方法一般会提到先装nvidia驱动,再cuda,再cudnn之类)。我今天尝试安装cuda 11.7时,发现cuda会自动安装nvidia驱动,如下图。由于我已经安装了更高版本的驱动,所以安装cuda11.7时,安装cuda失败。后来我安装pytorch1.13.1时,会自动安装cuda。所以如果你安装cuda就不需要安装驱动了。如果你安装pytorch1.13.1的cuda版本,也不需要安装cuda了,但是我安装了nvida驱动,参考文章。原创 2023-01-04 17:19:27 · 1291 阅读 · 1 评论 -
DQN PYTORCH 玩FlappyBird
【代码】DQN PYTORCH 玩FlappyBird。原创 2022-12-28 14:58:50 · 334 阅读 · 0 评论 -
spinningup rendering 多边形
【代码】spinningup rendering 多边形。原创 2022-11-13 10:33:40 · 188 阅读 · 0 评论 -
pygame 动画初学
当参数为0,代表填充。参数为其他代表线宽。原创 2022-11-03 11:18:10 · 559 阅读 · 0 评论 -
mujoco填坑
【代码】mujoco填坑。原创 2022-10-27 09:44:02 · 1014 阅读 · 0 评论 -
spinningup源码学习一
从examples入手,理解ExperimentGrid。原创 2022-10-25 11:10:17 · 368 阅读 · 0 评论 -
kmeans 具体应用基站分配和Python代码
kmeans 具体应用基站分配和Python代码转载 2022-09-16 11:35:14 · 209 阅读 · 0 评论 -
gym FrozenLake 理解学习
0 左1下2右3 上奖励: 稀疏奖励, 全0,当到达目标奖励为1。终止:到达目标或者到达H>>> import gym>>> env = gym.make( "FrozenLake-v0", is_slippery=False)>>> env.reset()0>>> env.render()SFFFFHFHFFFHHFFG>>> env.step(0)(...原创 2022-03-07 11:48:16 · 2886 阅读 · 0 评论 -
python 穷举 排列组合
pythondef f(n): x = [ [e] for e in range(3)] if n==1: return x r = [] for i in x: for j in f(n-1): # print('34===j,i',j,i) j.append(i[0]) r.append(j) return r# print(f(1))rr = .原创 2022-03-04 11:46:54 · 3727 阅读 · 0 评论 -
pandas 分组 取最大值
import numpy as npimport pandas as pdimport randomimport sysdata = [[ random.randint(0,100), random.randint(0,1) ] for i in range(6)]data = pd.DataFrame(data,columns=['age','sex'],dtype=int)print('line=',str(sys._getframe().f_lineno), '\n',data).原创 2022-03-02 11:06:28 · 2257 阅读 · 0 评论 -
TF 网络可视化图的理解
代码用莫凡的。# View more python tutorial on my Youtube and Youku channel!!!# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg# Youku video tutorial: http://i.youku.com/pythontutorial# https://github.com/MorvanZhou/tutorials原创 2022-02-23 11:47:53 · 315 阅读 · 0 评论 -
安装spinningup填坑ERROR: Could not build wheels for mpi4py which use PEP 517
ERROR: Failed building wheel for mpi4pyFailed to build mpi4pyERROR: Could not build wheels for mpi4py which use PEP 517 and cannot be installed directlyInstallation — Spinning Up documentation在虚拟机中spinningup安装时,报错,简单粗暴的将setup.py中22行删除。好了。mpi4py应该..原创 2022-01-19 17:22:49 · 7779 阅读 · 7 评论 -
gym demo
import gymimport numpy as npenv = gym.make("AirRaid-v0")observation = env.reset()for _ in range(1000): env.render() action = env.action_space.sample() observation, reward, done, info = env.step(action) if done: observatio...原创 2022-01-19 14:43:19 · 557 阅读 · 0 评论 -
LabelEncoder, OneHotEncoder
LabelEncoder, OneHotEncoderfrom sklearn.preprocessing import LabelEncoder, OneHotEncoderimport numpy as npencoder_x=LabelEncoder()x = [[chr(i%3+ord('a')), i+1] for i in range(5) ]x= np.array(x )x[:,0]=encoder_x.fit_transform(x[:,0])print('LabelEn原创 2021-12-24 11:46:23 · 700 阅读 · 0 评论 -
四分位距IQR interquartile range
import matplotlib.pyplot as pltimport numpy as npx = np.array([-100, 12, 45, 30, 70, 36, 50, 40, 26, 38])print(sorted(x))a = np.quantile(x, 0.75) # 上四分之一数b = np.quantile(x, 0.25) # 下四分之一数print("平均数:", np.mean(x)) # 打印均值print("中位数:", n...转载 2021-12-24 10:17:09 · 2633 阅读 · 0 评论 -
matplotlib 散点图 scatter
import matplotlib.pyplot as pltfrom matplotlib.font_manager import FontPropertiesimport numpy as npx=np.random.rand(2,26)# font = FontProperties( ,size=14) plt.title(u'散点图示例',fontproperties="SimHei")# fontproperties="SimSun" (宋体)plt.scat...原创 2021-12-23 10:06:56 · 813 阅读 · 0 评论 -
pythorch(六) torch.gather理解
从完整数据中按索引取值例子一:torch.gather(t, 0, torch.tensor([[1, 0, 2], [1,2, 1]]))dim=0index[1, 0, 2], [1,2, 1]则取的值的索引是将index放在0维上(1,_) (0, _) (2,_ ); (1, _ ) (2,_ ) (1, _)然后_每行自动填充为0,1,2得到下标(1,0) (0, 1) (2,2 ); (1, 0) (2,1) (1, 2)从t中,取出下标值(1,0) (0, ...原创 2021-12-02 16:33:30 · 1148 阅读 · 0 评论 -
sklearn FKold K折交叉验证 k-fold cross validation
C:\Users\pcl>conda activate torch38(torch38) C:\Users\pcl>pythonPython 3.8.11 (default, Aug 6 2021, 09:57:55) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32Type "help", "copyright", "credits" or "license" for more information.>>&g.原创 2021-12-01 09:59:33 · 371 阅读 · 0 评论 -
networkx 有向图 无向图demo
NetworkX — NetworkX documentation无向图有向图如果保存图片使用:plt.savefig('d:/a.png')原创 2021-11-16 11:15:16 · 528 阅读 · 0 评论 -
pythorch(五) Softmax理解
>>> import torch>>> import torch.nn.functional as F>>> from math import *>>> a=torch.tensor( [-2.1441, 1.8928, 0.45])>>> F.softmax(a)tensor([0.0141, 0.7975, 0.1884])>>> x = pow(e, a[0])>...原创 2021-11-12 11:24:04 · 1235 阅读 · 0 评论 -
2021-03-11 舒尔特方格 python3 pyqt5
重写了16遍的代码,改成循环体后一直不能正常工作。必须写16行。很怪。import sysimport randomimport timefrom PyQt5.QtWidgets import (QWidget, QGridLayout, QPushButton, QApplication,QLabel,QLineEdit) class Example(QWidget): def __init__(self): super().__init..原创 2021-03-11 16:45:52 · 402 阅读 · 3 评论 -
apriltag_ros 坐标转换
将机载端相机坐标系下的表示 fly_p 转换为tag坐标系下的向量tag_p def tag_callback(self,data): # print len(data.detections ) # useid =-1 if len(data.detections )>0: q = data.detections[0].pose.pose.pose.orientation q ...原创 2021-02-01 15:38:34 · 967 阅读 · 0 评论 -
python 四元数 numpy 矩阵乘法
>>> from tf.transformations import *>>> from tf import transformations>>> dir(transformations)['Arcball', '_AXES2TUPLE', '_EPS', '_NEXT_AXIS', '_TUPLE2AXES', '__builtins__', '__doc__', '__docformat__', '__file__', '__name__',.原创 2021-01-27 10:47:05 · 1528 阅读 · 3 评论 -
Python 继承 override 重写
class Parent: def myMethod(self): print ('fat') class Child(Parent): def myMethod(self): print ('sun') c = Child() c.myMethod() super(Child,c).myMethod() #!/usr/bin/python# -*- coding: UTF-8 -*- c..原创 2020-11-03 10:03:05 · 434 阅读 · 0 评论 -
python安装包的路径
如何查找python安装包的路径site-packages?使用命令:python -m sitepython-m site--user-site注意当查看指定版本的python的安装包时,需要指定python版本,比如python2.7.15 -m site>>> import pymavlink>>> import imp>>> imp.find_module('pymavlink')(None, '/home/z..原创 2020-07-22 13:05:39 · 866 阅读 · 0 评论 -
python^M bad interpreter: no such file or directory
很多情况下python作为脚本语言编写的脚本都是在win上用IDE写好,自动化sync到服务器上,如果全部都是由IDE部署上去的一般不是很容易出问题,但是部署完之后在生产环境用vim稍作修改,往往会出现问题。如:#! /usr/bin/python# coding=utf-8... ...实际运行报错:/usr/bin/python^M: bad interpreter: No such file or directory 1 2 3 4仔细检查报错内容,...原创 2020-07-21 10:09:59 · 621 阅读 · 0 评论 -
ImportError: No module named uinput
到pypi官网搜索https://pypi.org/project/python-uinput/https://pypi.org/project/python-uinput/有时候pypi官网连接不上。换个时段再试试。全靠运气原创 2020-04-17 15:17:57 · 452 阅读 · 0 评论 -
ubuntu下用boost python进行c++ python3混合编程
sudo apt-get install libboost-python-devbot_curve.cpp#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <boost/python.hpp>#inc...原创 2020-03-20 16:48:07 · 1387 阅读 · 0 评论 -
rov 调试单个电机
https://github.com/RaspberrySun/BlueROV2/blob/master/pid_controller.py# 设置每个推进器的pwm def set_motor_pwm(channel, pwm): master.mav.command_long_send(master.target_system, master.target_co...原创 2020-01-16 15:15:26 · 469 阅读 · 0 评论 -
python tkinter grid button label用法demo
#!/usr/bin/python3# -*- coding: UTF-8 -*-import numpy as npimport randomimport pandas as pd#!/usr/bin/python# -*- coding: UTF-8 -*- from tkinter import * # 导入 Tkinter 库 import os...原创 2019-12-12 18:40:47 · 526 阅读 · 0 评论 -
python 文件遍历 重新命名 解压tar.gz文件命令
$ tar -xzvf *.tar.gzlist = os.listdir(rootdir) # 列出文件夹下所有的目录与文件注: forroot,dirs,filesinos.walk(fileDir):print(root)#当前目录路径 print(dirs)#...原创 2019-10-30 10:16:14 · 1349 阅读 · 0 评论 -
python2 移除重复的c c++头文件
哈哈,实现了简单功能. 很多特殊情况没有考虑. 参数是文件名, 不要有路径名. 可以正常工作import sysdef getheader(s): a = s.find('#include') if a==-1: return '',False a = s.find('/*') b = s.find('*/') if b>a: s = s[0:a]+s[b+2:]...原创 2019-10-12 17:56:59 · 236 阅读 · 0 评论 -
tensorflow 激活函数 elu exponential
#!/usr/bin/env python3 # -*- coding:UTF-8 -*- import tensorflow as tfimport numpy as npfrom tensorflow.python import debug as tf_debug#tf.keras.backend.set_session(tf_debug.LocalCLIDebugWrap...原创 2019-03-28 14:54:24 · 2321 阅读 · 0 评论 -
q-learn
import numpy as npa = np.zeros(16)a[6]=-1a[9]=-1a[10]=1a = np.reshape (a,(4,4))print(a)mapp = aqtable = np.zeros((16,4))# up ,down, left ,right scorerate = 0.4#learning ratey = 0.4row ...转载 2019-04-11 16:22:45 · 248 阅读 · 0 评论 -
pandas 操作 加减行 对列数据进行修改 行遍历 从身份号码列提取出年月日
代码托管在githubhttps://github.com/sofiathefirst/AIcode/tree/master/06pandasAPIcsv 文件内容name,se,id李铭,1,44030119610508林路陶,2,44020319620319李琳,2,44030119880703刘国平,1,44030119690319import pandas as ...原创 2019-04-12 15:25:01 · 3371 阅读 · 0 评论 -
利用pandas做数据分析统计应用---统计二胎年龄差距
https://github.com/sofiathefirst/AIcode/tree/master/06pandasAPI源码和数据文件见上述链接。本文数据提取自深圳市2019年某次公租房申请公示名单,移除了非身份证的数据。import pandas as pdimport matplotlib.pyplot as plt '''粗略统计二胎年龄差距se 为1 主申请人,...原创 2019-04-12 16:48:29 · 627 阅读 · 0 评论 -
keras 线性回归 预测
#!/usr/bin/env python# -*- coding:UTF-8 -*-import numpy as npnp.random.seed(1337) # for reproducibilityfrom keras.models import Sequentialfrom keras.layers import Denseimport matplotlib.pyplot...原创 2019-04-03 19:01:33 · 812 阅读 · 0 评论