自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(29)
  • 收藏
  • 关注

原创 adata.X/numpy.matrix 改变维度失败

在 NumPy 中,numpy.matrix 是一个矩阵类,它是 numpy.ndarray 的一个子类,主要用于二维数据。numpy.matrix 对象,并且想要改变它的维度,你可以使用 numpy.reshape 函数。这里的 is_expressed 变成一维,为此我使用了 reshape(-1) 和 squeeze(),但是失败了,依然是二维,所以无论如何转化 is_expressed 依然是一个二维矩阵,我们只要把 numpy.matrix 转化为数组,这样可以解决。

2024-01-25 16:14:02 348

原创 为什么要写 python if __name__ == ‘__main__‘: 是什么意思,有什么作用

当我们刚开始编程时,定义的函数和执行的命令全部放在一个文件中,也不存在什么调用,没有使用 if。’,下面的代码会执行之类的,完全搞不懂!典型的中式为了解释而解释。函数外面的命令)以正常初始化定义的函数。文件里我们在函数的外面写了一点测试函数是否可正常运行的代码,并打印。’: 下,这样当导入这个函数的时候函数外面的顶层代码将不会被使用。’: 有什么作用,网上会告诉你当这个文件为当前执行文件时。当我们开始熟练时,我们开始将函数放在一个统一的文件里,例如。的所有命令,这就是python的逻辑:即使你只是导入。

2023-08-23 13:21:21 291

原创 【pytorch】使用 nn.LayerNorm 后,输出变为0

产生这一现象的原因是在 Parameter 初始化的时候使用了 nn.init.xavier_uniform_(parameter) 函数。

2022-07-08 17:20:55 973 1

原创 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 935

原创 ImportError: No module named wget

对于没有管理权限的使用者使用以下命令来安装:conda install -c conda-forge python-wget

2022-03-25 18:37:19 592

原创 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 2016

原创 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 24372 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 17894

原创 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 474

原创 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 2586

原创 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 2540

原创 理解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 125

原创 bashrc: line 6: syntax error near unexpected token `$‘in\r‘‘

由于使用WinSCP编辑bashrc文本,WinSCP会进行转化,将\n变为\rdos2unix .bashrc将你的文件转化成unix格式

2019-11-07 15:55:41 689 1

原创 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 10478 2

原创 Linux外环境用了conda内环境的包

因为加了export PATH=/home/yourname/miniconda3/bin:$PATH这样导致系统一直从conda内部检索应该改成判断语句__conda_setup="$('/home/yourname/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"if [ $? -eq 0 ]; then ...

2019-11-07 15:47:39 154

原创 Linux 安装 conda WARNING: md5sum mismatch of tar archive

安装 conda 时发现抱错:WARNING: md5sum mismatch of tar archive,最后发现是MD5校对错误在Windows下的文本文件用ssh上传到Unix/Linux,会自动进行格式转换,就是把回车、换行转为换行,在Unix下查看,会发现少了^M。将文件改为zip文件后再传输,传到linux上后改回sh,就可以成功安装。参考:https://www.lin...

2019-11-06 13:57:43 7118 9

原创 python cv.resizeWindow() takes at most 2 arguments (3 given)

cv2.resizeWindow(name, width, height) 后面两个长度参数只支持整数,若输入为浮点数则会出现上述错误。

2019-10-07 09:56:49 1994

原创 列表双输出和筛选

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 118

原创 理解 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 1651

原创 类方法/类函数第一个参数为什么是“self”?

类方法是对类中定义的函数的称呼,有别于一般函数的是,它的第一个参数是固定的,表示类实例化后实例本身。为什么类方法的第一个参数必须为指代实例本身的参数?

2019-07-19 10:30:50 5311 2

原创 Vue 组件传导主函数中的data

若组件中的模板var Bar = Vue.extend({ template: `<div></div>` , props: ["data1"], methods:{ handleSelect(key, keyPath) { console.log(key, keyPath); ...

2019-07-04 19:42:54 169

原创 javascript if 语句 不加花括号

只作用于最近的语句if(true) console.log('a') console.log('b')assertabif(false) console.log('c') console.log('f')assertfif(false) console.log('c') console.log('f...

2019-06-28 21:50:44 5662 3

原创 个人电脑部署django服务器

在网上查了很多代码都是错的,唯独http://www.opython.com/1043.html是好的,推荐给大家;此外如果大家设置了防火墙后外网还是访问不了,看看自己的电脑有没有使用VPN代理,停用是在上述条件下一种可能的解决方法。...

2019-06-15 19:08:17 483

原创 Keras自定义层

例子为单输入单输出层匿名函数定义Lambda(lambda x: (x - 100)/255, input_shape=(784,))#Lambda若作为第一次,需要指定input_shape自定义函数class MyLayer(Layer): def __init__(self, output_dim, **kwargs): self.output_dim ...

2019-06-03 21:23:24 406 3

原创 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 271

原创 Keras AttributeError: 'NoneType' object has no attribute '_inbound_nodes'报错

很多原因会引发这个“错误”这里列举一个由封装对象错误引发的原因将所有层封装需要所有的封装单位是Layer而非Tensor,在字符包埋后,由于Conv2D需要提供channel维度,所以一开始使用reshape命令使tensor维度增加,这个函数使x的属性变为Tensor而非Layer,所以引起封装错误,使用Lambda函数或Reshape 层函数解决,提供简短代码如下:embedded = ...

2019-05-29 21:22:33 6695 2

原创 函数 嵌套 串联使用 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 280

原创 关于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 217

转载 pydot failed to call GraphViz.install and ensure that its executables are in the $PATH解决方法

工作平台:Spyder1.确保你尝试了网上所有的解决方法包括(添加路径)2.pip install pydot==1.2.3此方法只保证此文章编辑时有效。此方法发现于 https://blog.csdn.net/u013093426/article/details/81164083 评论区,由qq_36785308用户提出。...

2019-05-09 21:00:44 292 1

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除