python
python学习笔记
Da_Shan_
这个作者很懒,什么都没留下…
展开
-
python去除特定字符
python 去除特定字符原创 2022-07-16 16:10:12 · 1065 阅读 · 0 评论 -
python 类中 __call__ 和 __getitem__ 的用法
python 类中 __call__ 和 __getitem__ 用法原创 2022-06-26 12:26:15 · 460 阅读 · 0 评论 -
python 和 pytorch中的矩阵乘法
python和pytorch中的矩阵乘法原创 2022-05-28 23:08:54 · 554 阅读 · 0 评论 -
functools partial详解
直接举例说明from functools import partialdef add_func(a, b): return a + bif __name__ == "__main__": add_test1 = partial(add_func, 1) print(add_test1(2)) # 3 print(add_test1(4)) # 5我们首先定义一个函数 add_func ,它传入两个参数,返回这两个参数之和,接着使用 partial 定义 a原创 2022-05-26 00:00:00 · 311 阅读 · 0 评论 -
os.walk()
os.walk()主要用来扫描某个指定目录下所包含的子目录和文件。os.walk() 返回的三个参数分别表示:curdir:当前目录dirs:该目录下包含的子文件夹files:该目录下包含的子文件for curdir, dirs, files in os.walk(root): # 遍历root下每一个文件 for file in files: fn_path = os.path.join(curdir, file) print(fn_path) #原创 2022-05-05 23:40:24 · 442 阅读 · 0 评论 -
python统计某一元素出现的次数
from collections import Counterarr = [1,2,5,1,1,5,6,3,3,2,2,4,8]# 方法一:利用python自带的包来解决res1 = Counter(arr)# 方法二:自定义函数def count_char(arr): res = dict() for i in arr: if i not in res.keys(): res[i] = 0 res[i] += 1 return resres2 = count_char原创 2022-04-29 17:27:37 · 1351 阅读 · 0 评论 -
Python中函数eval和ast.literal_eval的区别详解
https://zhuanlan.zhihu.com/p/29881075众所周知在Python中,如果要将字符串型的list,tuple,dict转变成原有的类型呢? 这个时候你自然会想到eval. eval函数在python中做数据类型的转换还是很有用的。它的作用就是把数据还原成它本身或者是能够转化成的数据类型.下面来看看示例代码:# str => lista = '[1, 2, 3, 4]'res = eval(a)print(a, type(a)) # [1, 2, 3, 4] &转载 2022-04-17 14:08:27 · 574 阅读 · 0 评论 -
sublime主题配色
{“ignored_packages”:[“Vintage”,],“theme”: “Default Dark.sublime-theme”,“dark_theme”: “Default.sublime-theme”,“light_theme”: “Adaptive.sublime-theme”,“color_scheme”: “Monokai.sublime-color-scheme”,“font_size”: 15,}{“cmd”: [“C:\Users\weihu\anacon原创 2022-04-17 10:07:13 · 932 阅读 · 0 评论 -
numpy 索引和相关的mask操作
numpy 索引和相关的mask操作原创 2022-04-12 10:48:04 · 3025 阅读 · 0 评论 -
nunpy.delete()
基本说明def delete(arr, obj, axis=None): """ Return a new array with sub-arrays along an axis deleted. For a one dimensional array, this returns those entries not returned by `arr[obj]`. Parameters ---------- arr : array_like原创 2022-04-12 09:25:53 · 72 阅读 · 0 评论 -
python log函数
python log函数语法:import math math.log(x[, base])注意:log()是不能直接访问的,需要导入 math 模块,通过静态对象调用该方法。参数:x : 数值表达式base :可选,底数,默认为e实例import math# 以10为底数print(math.log(100, 10)) # 2.0# 以e为底数print(math.log(math.e)) # 1.0# 以5为底数print(math.log(25, 5)) # 2.0原创 2022-04-07 08:32:35 · 4455 阅读 · 0 评论 -
Docker学习
Docker中的一些名词镜像(Image)Docker中的镜像就好比是一个模板,通过这个模板来创建容器服务,最终的服务运行和项目运行就是在容器中的容器(container)仓库(repository)仓库就是来存放镜像的地方仓库分为公有仓库和私有仓库...原创 2022-02-06 15:34:42 · 512 阅读 · 0 评论 -
pickle模块
Python 中有个序列化过程叫作 pickle,它能够实现任意对象与文本之间的相互转化,也可以实现任意对象与二进制之间的相互转化。也就是说,pickle 可以实现 Python 对象的存储及恢复。pickle 模块提供了以下 4 个函数供我们使用:dumps():将 Python 中的对象序列化成二进制对象,并返回;loads():读取给定的二进制对象数据,并将其转换为 Python 对象;dump():将 Python 中的对象序列化成二进制对象,并写入文件;load():读取指定的序列化数转载 2022-01-06 11:03:55 · 578 阅读 · 0 评论 -
collections之OrderedDict
如果想让字典有序,可以使用collections.OrderedDict,它现在在C中实现,这使其快4到100倍。collections.OrderedDict基本使用将类OrderedDict实例化会得到一个dict子类的实例,支持通常的dict方法。from collections import OrderedDictod=OrderedDict()print(isinstance(od,OrderedDict)) # Trueprint(isinstance(od,dict)) # Tr转载 2022-01-06 10:50:33 · 189 阅读 · 0 评论 -
Python
img = cv2.imread("./lena.jpeg")img = img[:,:,::-1]# img = img[..., ::-1]plt.imshow(img)plt.show()原创 2021-12-16 13:38:49 · 3530 阅读 · 0 评论