随笔分类 - Python学习
摘要:Jupyter Notebook (.pynb)是一个集bash脚本和Python脚本为一体的、交互式脚本文件 安装install 建议conda安装:conda install jupyter 启动 Running the Notebook jupyter notebook VSCode中使用 V
阅读全文
摘要:np.tofile np.fromfile np.random.random np默认数据类型 常用的切片操作 反转数组 # CHW --> HWC, torch.tensor --> np.ndarray, RGB --> BGR image = image.permute(1, 2, 0).nu
阅读全文
摘要:Why C++ is faster than Python https://www.freecodecamp.org/news/python-vs-c-plus-plus-time-complexity-analysis/ Summary Table 编程语言 strongly typed ? 跨平
阅读全文
摘要:一、安装 pip install opencv-python 二、图像读写 cv2.imread(path, flag) 返回值类型:np.ndarray cv2.imwrite(filename, image) 三、图像编辑 cv2.resize() 图像缩放,默认方式为cv2.INTER_LIN
阅读全文
摘要:一、OpenCV图像读取 import cv2 image = cv2.imread(image_path) # BGR # print(image.shape) # [H, W, C] cv2.imshow("window1", image) cv2.waitKey(0) opencv-pytho
阅读全文
摘要:一、Python读写txt文件 1.1 python读取txt文件 in_text_file = "xxx.txt" with open(in_text_file) as f: lines = f.readlines() lines = [line.strip() for line in lines
阅读全文
摘要:Python自带os.path库相关函数 一、判断文件/路径是否存在 os.path.isfile() os.path.isdir() os.path.exists() 可缩写为:import os.path as osp 返回值:True/False 二、创建文件夹 os.makedirs() i
阅读全文
摘要:argparse 命令行参数 Code Snippet 1 import argparse if __name__ == "__main__": # parse argument parser = argparse.ArgumentParser() parser.add_argument("dept
阅读全文
摘要:range函数 range(start, stop[, step]) [start, stop) 区间左闭右开,同切片操作 >>> for i in range(5): ... print(i) >>> 1 2 3 4 5 字典的元素个数 len(dict) 返回字典中的元素(键值对)个数 Pyth
阅读全文
摘要:使用Python虚拟环境的必要性 不同Python工程中用到的包不尽相同,相同包的版本也可能不一样,一种方法是使得各个环境相对独立。 假如说某一个环境崩了,直接remove掉就可以了,不会影响到其他环境。不同虚拟环境之间互不影响。 一、下载&安装 Linux系统安装Anaconda3 [官网] [清
阅读全文