随笔分类 -  Python基础

私有变量
摘要:通过对象名.__dict__来查看,然后再访问私有变量。 与上面的同理,现在私有方法的访问同样: 如上图示,后期添加的__y的名字并不会被改变;由此可知,名字改变是发生在类实例化对象的时候; 阅读全文

posted @ 2022-06-27 00:34 lmqljt 阅读(67) 评论(0) 推荐(0)

mixin方法
摘要:以下参考:https://www.bilibili.com/video/BV1c4411e77t?p=63&vd_source=3ad05e655a5ea14063a9fd1c0dcdee3e 一般起mixin名字的类名,都是后来为了添加某个功能而加进去的。 重写就是实现类继承的多态 阅读全文

posted @ 2022-06-27 00:16 lmqljt 阅读(42) 评论(0) 推荐(0)

类继承、多态、继续和继承顺序、__init__,钻石继承,MRO等
摘要:类继承:class C(A,B): c=C() c.methods依次从A和B中找methods,只有在其自身的C类中找不到了,且在A中也找不到了,才会去B中寻找。也就是说继承的顺序是从左到右的。 组合/嵌套继承,嵌套类: 构造函数: 钻石继承: B2,B2各一次。 MRO(Method Resol 阅读全文

posted @ 2022-06-26 23:27 lmqljt 阅读(150) 评论(0) 推荐(0)

torch.ones_like(),expand_as(),expend()等torch.repeat
摘要:https://blog.csdn.net/Arthur_Holmes/article/details/104267662 https://blog.csdn.net/weixin_39568781/article/details/110066146 https://blog.csdn.net/qq 阅读全文

posted @ 2022-05-09 16:05 lmqljt 阅读(675) 评论(0) 推荐(0)

梯度与导数的关系
摘要:转载自:https://blog.csdn.net/whu_student/article/details/77918020 阅读全文

posted @ 2022-05-09 15:45 lmqljt 阅读(51) 评论(0) 推荐(0)

本地创建的jupyter notebook 无法连接本地环境(即不能运行代码)
摘要:参考:https://www.cnblogs.com/damin1909/p/12691147.html 本人所用的python是anaconda下的,由于需求不同,创建了好多个python用于不同的目的,但是,今天创建的一个环境,在下载好jupyter notebook之后,虽然能在浏览器上打开, 阅读全文

posted @ 2022-05-08 21:58 lmqljt 阅读(1363) 评论(0) 推荐(0)

pip常见使用方法
摘要:pip可以理解类似yum管理rpm包的管理python包工具 pip --help Usage: pip <command> [options] Commands: install 安装包 uninstall 卸载包 freeze 按照一定格式输出已经安装的包列表 list 列出已经安装的包 sho 阅读全文

posted @ 2022-05-08 21:56 lmqljt 阅读(237) 评论(0) 推荐(0)

np.r_、np.c_、np.concatenate和np.append
摘要:np.r_是按行连接两个矩阵,就是把两矩阵上下相加,要求列数相等,最终结果的行数为两个矩阵行数和。 np.c_是按列连接两个矩阵,就是把两矩阵左右相加,要求行数相等,最终结果的列数等于两矩阵的列数和。 np中的矩阵合并np.c_[matrix]只能按照列拼接(横向扩展原来句子的维度) np中的矩阵合 阅读全文

posted @ 2022-05-08 14:10 lmqljt 阅读(462) 评论(0) 推荐(0)

Python中plt.plot()、plt.scatter()和plt.legend函数的用法示例
摘要:参考:http://www.cppcns.com/jiaoben/python/471948.html https://blog.csdn.net/weixin_44825185/article/details/105688701 https://blog.csdn.net/qq_43186282/ 阅读全文

posted @ 2022-05-08 11:13 lmqljt 阅读(704) 评论(0) 推荐(0)

PyTorch的Variable已经不需要用了!!!
摘要:转载自:https://blog.csdn.net/rambo_csdn_123/article/details/119056123 Pytorch的torch.autograd.Variable今天在看《莫凡Python》的PyTorch教程的时候发现他的代码还在使用Variable,并且我记得过 阅读全文

posted @ 2022-05-07 18:21 lmqljt 阅读(380) 评论(0) 推荐(0)

csv.reader(f)和f.readlines()、追加数据
摘要:假如某个文档f中存储如下内容: 你好,中国。 1,2,3,4 共两行内容。 当你使用csv.reader(f),则会存储为如下形式; [['你','好','中','国'] ['1','2','3','4']] 如果使用f.readlines()则结果为: ['a,b,c,d\n','1,2,3,4\ 阅读全文

posted @ 2022-04-14 13:54 lmqljt 阅读(271) 评论(0) 推荐(0)

model.apply(fn)或net.apply(fn)
摘要:详情可参考:https://pytorch.org/docs/1.11/generated/torch.nn.Module.html?highlight=torch%20nn%20module%20apply#torch.nn.Module.apply 首先,我们知道pytorch的任何网络net, 阅读全文

posted @ 2022-04-14 11:25 lmqljt 阅读(734) 评论(0) 推荐(0)

Python with语句和上下文管理器
摘要:open("FishC.txt","w")#此处需注意如果被打开的文件中,已有内容,那么用w的方式打开,则会导致原文件内容被截断,也就是相当于被清空了,然后重新写入的意思。然后我们把打开后产生的文件对象赋值给 f 变量。 然后我们调用文件对象 f 的write方法来写入一个字符串。其返回的是写入的字 阅读全文

posted @ 2022-04-13 20:59 lmqljt 阅读(70) 评论(0) 推荐(0)

Python3 collections模块
摘要:https://www.cnblogs.com/zhangxinqi/p/7921941.html http://www.wjhsh.net/meng-wei-zhi-p-8259022.html https://blog.csdn.net/asialee_bird/article/details/ 阅读全文

posted @ 2022-04-12 15:40 lmqljt 阅读(24) 评论(0) 推荐(0)

python变量名下划线
摘要:xx: 公有变量 _x: 单前置下划线,保护变量,私有化属性或方法,不能用于’from module import *’ 以单下划线开头的表示的是protected类型的变量。即保护类型只能允许其/类对象本身与子类对象进行访问。是一个Python命名约定,表示这个名称是供内部使用的。 它通常不由Py 阅读全文

posted @ 2022-04-12 15:19 lmqljt 阅读(1822) 评论(0) 推荐(0)

Python中__call__的用法
摘要:可参考: https://www.cnblogs.com/yeer-xuan/p/13497494.html 阅读全文

posted @ 2021-09-10 18:29 lmqljt 阅读(44) 评论(0) 推荐(0)

transforms.py
摘要:from PIL import Image from torchvision import transforms #python的用法--》tensor数据类型 #通过transforms.ToTensor来看两个问题 #1. 如何使用transforms(python) #2. 为何需要Tenso 阅读全文

posted @ 2021-09-06 14:48 lmqljt 阅读(43) 评论(0) 推荐(0)

python 的 @staticmethod和@classmethod和普通实例方法
摘要:参考:https://www.huaweicloud.com/articles/12607084.html https://blog.csdn.net/qq_30708445/article/details/89552569 阅读全文

posted @ 2021-09-01 22:58 lmqljt 阅读(29) 评论(0) 推荐(0)

Python 有序字典(OrderedDict)与 普通字典(dict)
摘要:可参考: https://zhuanlan.zhihu.com/p/98946805 https://www.cnblogs.com/notzy/p/9312049.html 阅读全文

posted @ 2021-09-01 20:30 lmqljt 阅读(65) 评论(0) 推荐(0)

Python装饰器,Python闭包
摘要:可参考:https://www.cnblogs.com/lianyingteng/p/7743876.html suqare(5)等价于power(2)(5);cube(5)等价于power(3)(5); power相当于是一个工厂,由于参数不同,得到了两个不同的生产线,一个是square一个是cu 阅读全文

posted @ 2021-08-26 21:37 lmqljt 阅读(63) 评论(0) 推荐(0)

导航