python笔记

Python笔记

杂项

列表遍历

1
2
3
4
5
# 整数步长
for i in range(1,10,2) # start,end,step
# 小数步长
for i in np.arrange(0,1,0.01) #start,end,step
for i in np.linspace(0,0.9,10) # 0-0.9的10等分

查看gpu情况

1
2
# 在命令行里
nvidia-smi

绘图

matpltlib

matplotlib是一个最大的绘图库,包括了pyplot、pylaib等基础绘图库。

1
import matplotlib.pyplot as plt
  • 标题
1
2
plt.title("title") # 括号当中输入标题的名称
plt.rcParams['font.sans-serif']=['SimHei'] # 中文标题时避免乱码
  • Figure对象
1
2
3
plt.figure(figsize=(6, 3))
plt.plot(6, 3)
plt.plot(3, 3 * 2)
  • 坐标轴
1
2
3
4
5
plt.xlim(0,6) #x轴坐标轴
plt.ylim((0, 3))#y轴坐标轴
plt.xlabel('X')#x轴标签
plt.ylabel('Y')#y轴标签
plt.rcParams['axes.unicode_minus']=False # 负数避免乱码
  • 注释箭头
1
plt.annotate(text='标记点',xy=(3,np.sin(3)),xytext=(4,-0.5),weight='bold',color='b',arrowprops=dict(arrowstyle='-|>',color='k'))

git

基本步骤

  1. 添加公钥:everything搜索id_rsa.pub,复制其中内容到github/gitee

  2. 克隆仓库到本地

    1
    git clone https://gitee.com/momaoto/fourth-assignment.git
  3. 进入文件夹初始化仓库

    1
    git init
  4. 关联远程仓库

    1
    2
    3
    git remote add origin https://gitee.com/momaoto/fourth-assignment.git
    git remote rm origin
    git remote -v

    origin为后面链接所指远程库的别名,方便操作

  5. 拉取远程分支与本地仓库合并

    1
    git pull origin master:main
  6. 代码添加进本地暂存区

    1
    2
    git add .
    git add test.txt
  7. 确认提交记录到本地仓库

1
2
git commit .
git commit test.txt
  1. 安装子模块
1
2
3
# 根目录下
git submodule init
git submodule update

命令大全

1
2
3
4
5
6
7
git remote:不带任何参数直接运行 git remote,将会列出当前仓库中已经配置的远程仓库的简写名称列表。
git remote -v:显示当前仓库中已经配置的远程仓库的简写名称和对应的URL。
git remote add <name> <url>:将一个新的远程仓库添加到当前仓库中。<name>是远程仓库的简写名称,<url>是远程仓库的URL。
git remote rename <old-name> <new-name>:将已经存在的远程仓库的简写名称重命名为新的名称。
git remote remove <name>:从当前仓库中移除指定的远程仓库。
git remote set-url <name> <new-url>:修改指定远程仓库的URL。
git remote show <name>:显示指定远程仓库的详细信息,包括URL和跟踪分支。

设置私人令牌

1
git remote set-url origin https://<your_token>@github.com/<USERNAME>/<REPO>.git

暂存区

1
git ls-files

查看代码行数

1
git ls-files | xargs wc -l
1
2
Username for 'https://gitee.com': momaoto
Password for 'https://momaoto@gitee.com': 私人令牌

git原理:

conda

创建新环境

1
conda create --name mesh2gs python=3.10

激活环境

1
conda activate mesh2gs

退出当前环境

1
conda deactivate

查看已有环境

1
conda env list

删除不需要的环境

1
conda env remove --name myenv

清理缓存

1
2
pip cache purge
conda clean --all