![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
huahuahuahhhh
一步一步,慢慢来
展开
-
python从列表中随机取数
从列表中随机取数原创 2023-01-05 15:07:35 · 5606 阅读 · 1 评论 -
python类中调用未定义的函数
python类中调用未定义的方法原创 2022-08-25 14:06:34 · 1442 阅读 · 0 评论 -
python 删除非空文件夹
python中删除非空文件夹原创 2022-06-24 11:10:41 · 643 阅读 · 0 评论 -
python -m -u参数
执行python程序时,-m 和 -u 参数的意义python -u参考https://blog.csdn.net/wonengguwozai/article/details/81668240python中标准错误(std.err)和标准输出(std.out)的输出规则 ——标准输出默认需要缓存后再输出到屏幕,而标准错误则直接打印到屏幕—————————————————————————————————————————————————————————python命令加上-u(unbuffer原创 2022-05-25 17:49:32 · 766 阅读 · 0 评论 -
shell向python传递参数
shell向python传递参数原创 2022-05-25 17:08:01 · 3764 阅读 · 0 评论 -
python中的@property装饰器
1. property摘抄自https://blog.csdn.net/qq_41359051/article/details/82939655定义类的函数时,在函数上方加@property它的作用是:将方法变成属性调用class Stranger(object): def __init__(self, gender=None, age=None, job=None): self.gender = gender self._age = age # 这里原创 2022-05-11 09:53:49 · 443 阅读 · 0 评论 -
onnx模型修改输入维度
代码参考这个代码实现将原始onnx模型的第一个维度修改为sym_batch_dim=1import onnxdef change_input_dim(model): # Use some symbolic name not used for any other dimension sym_batch_dim = "1" # or an actal value actual_batch_dim = 4 # The following code changes原创 2022-04-27 14:20:11 · 2681 阅读 · 2 评论 -
python中argparse模块
参考官方文档https://docs.python.org/zh-cn/3/library/argparse.html#nargspython中参数解释器,实用流程:import argparseparser = argparse.ArgumentParser() ## 新建参数解释器对象parser.add_argument('-v') ## 添加参数args = parser.parse_args(['-v', '3'])### 参数赋值,也可以通过终端赋值'''python test.p原创 2022-01-15 16:32:52 · 798 阅读 · 0 评论 -
__call__()
参考链接http://c.biancheng.net/view/2380.html有__call__()的类,使得类对象可以通过对象名()调用类的__calll__()原创 2021-05-12 19:50:52 · 112 阅读 · 0 评论 -
类中的函数
找不到check2函数。python 不会在类内调用函数。要么将check2定义为全局函数,要么check2带参数self,调用的时候是self.check2(…)原创 2021-04-19 20:20:32 · 173 阅读 · 0 评论 -
for循环
y = [1, 2, 3, 4,5,6]for x in y: print(y) print(y.pop(0))输出为什么输出的结果是这样的呢?官方有一个for循环的解释There is a subtlety when the sequence is being modified by the loop (this can only occur for mutable sequences, e.g. lists). An internal counter is used to kee原创 2021-04-19 16:01:11 · 377 阅读 · 0 评论 -
if else复合语句
condition = Truer = 2 if condition else 3# 如果condition 为真,输出2,否则,输出3print(r)# 2condition = Falser = 2 if condition else 3# 如果condition 为真,输出2,否则,输出3print(r)# 3原创 2021-04-14 16:01:53 · 649 阅读 · 0 评论 -
格式化输出--对齐及补全
转载自https://www.cnblogs.com/qinchao0317/p/10699717.html左中右对齐及位数补全(1)< (默认)左对齐、> 右对齐、^ 中间对齐、= (只用于数字)在小数点后进行补齐(2)取位数“{:4s}”、"{:.2f}"等>>> print('{} and {}'.format('hello','world')) # 默认左对齐hello and world>>> print('{:10s} and {:&转载 2021-03-17 11:02:49 · 622 阅读 · 0 评论 -
python中常见的异常
python中的异常一、常见的异常ZeroDivision 除数为0IndexError 索引值超出范围(取列表或字符串中元素可能出现)KeyError 关键字在字典中不存在NameError 访问的变量不存在AssertionError 断言不成立(asser语句不成立)二、异常捕获try: 检测范围语句块except [异常类型1]: 处理代码1except [异常类型2]: 处理代码2...try执行到一个异常语句后,后面的异常语句不再执行,抛出相应的异常。tr原创 2020-12-18 19:51:18 · 176 阅读 · 1 评论 -
kfold
import numpy as npfrom sklearn.model_selection import GroupKFold,KFolddef group_k_fold(): ''' K-fold iterator variant with non-overlapping groups. 根据组来划分数据,不同组的类别与数据的折数相等。相同组里面的数据不会出现在两个不同的折中。 The same group will not appear in two differ原创 2020-12-06 16:14:03 · 213 阅读 · 0 评论 -
cls与self
cls这个参数表示自身类,它的作用有:调用类的属性,类的方法,实例化对象等。最后再说一下:类方法可以同时被对象和类本身调用!使用cls,必须在方法名前加classmethod装饰器@classmethodself则是类的一个实例对象。class Person(object): def __init__(self, name, age):# 自带参数self self.name = name self.age = age print('self:'原创 2020-12-06 15:49:19 · 284 阅读 · 0 评论 -
python中浅拷贝与深拷贝
id()获取对象的内存地址https://blog.csdn.net/qq_38556217/article/details/103002827https://www.cnblogs.com/fanyuchen/p/6947025.htmlhttps://blog.csdn.net/as480133937/article/details/87305247?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2allfirst_r.转载 2020-11-04 17:10:06 · 390 阅读 · 0 评论 -
numpy中数组维度的理解
这篇文章主要是为了弄清楚数组按每个维度进行计算时,具体的操作是什么样的。一、数组中的各个维度表示的是什么?为了便于理解,用最小单位体表示,剥去最外面一层中括号后,数据的形状。1. 以二维数组为例import numpy as npnp.random.seed(0)arr2 = np.random.randint(0,9,size=(4,3))print(arr2)[[5 0 3]...原创 2020-02-20 16:09:47 · 9744 阅读 · 8 评论 -
python解压文件到指定路径
os.walk(path)返回(root,dirs,files)os.path.isfile()判断是否是文件zipfile.is_zipfile(file_path)判断是否是zip文件import zipfileimport ospath = r''for p in os.walk(path):# (root,dirs,files) root = p[0] d...原创 2019-11-22 16:46:28 · 3268 阅读 · 0 评论 -
色块显示
色块显示参考import numpy as npimport matplotlib as mplimport matplotlib.pyplot as pltimport matplotlib.patches as mpatchesfrom sklearn.linear_model import LogisticRegressionimport pandas as pdpath =...原创 2019-11-01 17:23:05 · 498 阅读 · 0 评论 -
python读excel表格
python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是写excel的库import xlrddef read_excel(): path = './Sec_BLE_Zigbee.xlsx' book = xlrd.open_workbook(path) # 打开一个工作表 for sheet in book.sheets(...原创 2019-09-03 18:04:36 · 779 阅读 · 1 评论 -
正则表达式
一、概述1. 概念1.1 Regular Expression 一种文本模式,描述在搜索文本时要匹配的一个或多个字符串1.2 典型场景数据验证文本扫描文本提取文本替换文本分割1.3 语法字面值 普通字符 需转义 ,^,$,…元字符1.4 匹配单字,预定义的元字符 .除\n的所有字符 \d 数字,等同于[0~9] \D 非数字,等同于^[0~9] \s...原创 2019-08-25 18:07:36 · 267 阅读 · 0 评论 -
python--numpy
查看numpy.array的基本信息import numpy as npar = np.array([1,2,3,4,5,6,7])print(ar) # 输出数组,注意数组的格式:中括号,元素之间没有逗号(和列表区分)print(ar.ndim) # 输出数组维度的个数(轴数),或者说“秩”,维度的数量也称rankprint(ar.shape) #...原创 2019-06-18 10:49:15 · 379 阅读 · 0 评论 -
Python中怎么读写图像
Python中,主要使用的图像处理库是PIL(Python Imaging Library)、opencv、scikit-image1. 用PIL读写图片1from PIL import Imagepath = 'data/timg.jpg'img = Image.open(path)#读取图片print(type(img))#<class 'PIL.PngImagePlugin...原创 2019-06-04 14:21:31 · 4098 阅读 · 1 评论 -
Python函数及相关知识
__call__详解如果在类中实现了 call ,那么实例对象也将成为一个可调用对象原创 2019-06-01 17:37:51 · 116 阅读 · 0 评论 -
调试中的一些Python错误
Python出现bound method。方法没加()PermissionError: [Errno 13] Permission denied: '...\data\\input\\dev.csv'dev.csv这个文件打开了原创 2019-06-01 09:58:03 · 694 阅读 · 2 评论 -
数值与日期
一、数值1. 格式化一般形式‘数值:{:}’.format(a[0])显示正负号‘分数:{:-}’.format(a[0]) #显示正负号显示几位小数‘数值:{:.2f}’.format(a[0])显示百分比‘分数:{:.2%}’.format(1/5)2.小数位处理math.trunc() 截去小数部分import matha = [-2.9,-2.4,2.4...原创 2019-08-21 20:16:48 · 255 阅读 · 1 评论 -
python中json模块读写数据
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,易于人阅读和编写一、json字符串操作python对象转成json字符串json.dumps()及json字符串转为python对象json.loads()import jsondef json_dumps_loads(): data = {'first_name': 'Wonde...原创 2019-09-03 17:41:22 · 177 阅读 · 0 评论 -
python中csv模块读写文件
一、csv模块读文件1. csv.reader–可迭代对象通过索引获取文档内容def csv_read(): file = open('./txt/names.csv','r') reader = csv.reader(file) head = next(reader) print(head) for line in reader: p...原创 2019-09-03 15:26:20 · 1551 阅读 · 0 评论 -
python并发编程
一、概述二、多线程threadingthreading.Thread类直接生成线程实例定义两个threading.Thread线程实例,参数是待运行的函数,及函数的参数。通过遍历,使用.start()控制同时启动。threading.current_thread().name获取线程的名字,在threading.Thread初始化时没定义name,取到的是默认名.join()确...原创 2019-08-28 19:32:59 · 159 阅读 · 0 评论 -
系统工具
一、概念二、系统模块命令行参数sys.argvimport sysdef add(a,b): return a+ba,b= 0,0if sys.argv[1]: a = int(sys.argv[1])if sys.argv[2]: b = int(sys.argv[2])print(add(a,b))命令行键入python ans.py 2 ...原创 2019-08-27 22:03:16 · 195 阅读 · 0 评论