
Python
江浙沪讲吴语
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
python 顶层模块理解 ValueError: attempted relative import beyond top-level package
package_0├── module_0.py├── module_1.py├── package_1│ ├── __init__.py│ ├── module_2.py│ ├── module_3.py│ └── package_2│ ├── __init__.py│ ├── module_21.py│ └── module_22.py└── package_3 ├── __init__.py └── module原创 2022-04-15 22:35:12 · 1064 阅读 · 0 评论 -
Python Class super().__init__() 作用
在 python3 中为super()._init_()在 python2 中 为super(classname, self)._init_()先定义一个父类 A,里面的 init 构造函数class A: def __init__ (self, w): self.w = w def aa(self, a): a = self.w print(a)class B(A): def __init__ (self, w):原创 2022-02-25 21:07:02 · 2238 阅读 · 0 评论 -
Pytorch tensor 如何找到特定值的索引 (index)
使用 torch.nonzero(),返回非零值的索引 (index)其中 True 算作非零数,False 算作零,所以可以巧用判断式来找到 Tensor 特定值的索引import torcha = torch.arange(3*5).reshape(3,5).view(-1)b = torch.nonzero(a==10).squeeze()print(b) # tensor(10)...原创 2022-02-19 20:19:29 · 26942 阅读 · 1 评论 -
Python报错:local variable referenced before assignment
原因是在定义函数时,使用了与全局变量同名的局部变量a = 10b = 10def func(): if b == 5: a = 5 print(a)funk = func()这时会报错 ‘UnboundLocalError: local variable ‘a’ referenced before assignment’因为函数内部定义了一个与外部变量同名的变量,此时函数会把这个变量定义为局部变量,如果没有赋值则不能调用它。...原创 2022-02-19 20:01:10 · 18976 阅读 · 0 评论 -
list to array 报错 VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
报错信息:VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify ‘dtype=object’ when creati原创 2021-09-28 22:48:40 · 556 阅读 · 0 评论 -
TensorFlow 1.x 中查看 TF.tensor 的具体数值的两种方法
由于TensorFlow 1.x 由静态图构成,所以不能直接查看tensor的数值,而使用动态图的TensorFlow 2.x则可以直接查看TensorFlow 1有两中查看方式:第一种方法:import tensorflow.compat.v1 as tftf.disable_v2_behavior()sess = tf.Session()sess.run(tf.global_variables_initializer())tensor = tf.Variable([[1,2]])ses原创 2021-03-27 20:25:47 · 3147 阅读 · 0 评论 -
numpy array 数字范围设定
在处理 mnist 数据库,把数据库的数组加一发现,数组范围还是 [0, 255];发现把256的数切片加一等于零?原来是 mnist 数据库数组的数据类型是 “uint8”,最多256个数,把数据类型改成 “int” 成功使数组加一mnist = tf.keras.datasets.mnist(x_train, y_train), (x_test, y_test) = mnist.load...原创 2019-12-09 13:42:37 · 2674 阅读 · 0 评论 -
理解tf.pad
官方文档For each dimension D of input, paddings[D, 0] indicates how many values to add before the contents of tensor in that dimension, and paddings[D, 1] indicates how many values to add after the cont...原创 2019-11-13 21:28:02 · 169 阅读 · 0 评论 -
Conda Solving environment: failed with initial frozen solve. Retrying with flexible solve.
可能是用了较高版本的python导致不兼容引起的笔者用python3.8安装Tensorflow出现这个报错将python降级后解决conda install python=3.7原创 2019-11-07 15:51:34 · 10614 阅读 · 2 评论 -
python cv.resizeWindow() takes at most 2 arguments (3 given)
cv2.resizeWindow(name, width, height) 后面两个长度参数只支持整数,若输入为浮点数则会出现上述错误。原创 2019-10-07 09:56:49 · 2150 阅读 · 0 评论 -
列表双输出和筛选
a=[[1,'a'],[2,'b'],[3,'c']]for i,x in a: print(i,x)assert1 a2 b3 cl=[x for i,x in a if i<3]print(l)assert[‘a’, ‘b’]原创 2019-08-18 18:43:16 · 155 阅读 · 0 评论 -
理解 keras 中的 "Layer" 和 "Tensor"
keras 中有两个基本的概念:Layer 和 TensorLayer :是模型的组成单位,用于构建神经网络框架 在 keras 中用 大写的 module 表示,用于搭建纯模型框架,涉及到计算时使用属性 input 或 output 调出其 Tensor 如以下代码,多用于简单的 Sequential 结构(导入模块部分省略,python=3.7, keras=2.6)n_in = 5...原创 2019-08-08 17:03:13 · 1840 阅读 · 0 评论 -
类方法/类函数第一个参数为什么是“self”?
类方法是对类中定义的函数的称呼,有别于一般函数的是,它的第一个参数是固定的,表示类实例化后实例本身。为什么类方法的第一个参数必须为指代实例本身的参数?原创 2019-07-19 10:30:50 · 5793 阅读 · 2 评论 -
numpy.random.seed()使用
random.seed()设定完后所有的random.random()全部确定,直到重新设置random.seed();由random.seed()设定的随机数排列顺序不以时间,设备改变;没有设定random.seed(),则系统根据时间来自己选择这个值,此时每次生成的随机数因时间差异而不同。seed必须为正整数。from numpy import *num=0random.seed(5)...原创 2019-06-01 16:02:00 · 359 阅读 · 0 评论 -
函数 嵌套 串联使用 Python
先看例子:def get_early_stopping(monitor=5, patience=6): return get_model_path(a=monitor, b=patience)def get_model_checkpoint(model_path = 'Python'): return print('Why ' + model_path + ' is so d...原创 2019-05-25 17:26:20 · 350 阅读 · 0 评论 -
关于Python3 Class super() module的一些应用
来看例子:class A: def apam(self, c='1'): print('A.spam'+c)class B(A): def spam(self,c='2'): print('B.spam') super(B, self).apam(c='3') # is the same as 'super().apam(c='...原创 2019-05-25 17:07:24 · 286 阅读 · 0 评论