0、pandas和numpy的一些基本操作
(1)pandas的DataFrame转成ndarray
import pandas as pd
data = [['2019/08/01', 10],
['2019/08/01', 11]]
result = pd.DataFrame(data, columns=['ds', 'val'])
result.values
# result.values整体是个ndarray类型的数组
(2)pd.read_csv("文件名.csv",header=None)
这样一来第一行就也能读进去
(3)把ndarray保存成csv的一种方式
pd.DataFrame(array).to_csv('array.csv')
1、scipy中值滤波
来自:python 一维中值滤波signal.medfilt踩坑笔记_GodenEngineer的博客-CSDN博客_一维中值滤波
python的中值滤波使用起来,不如matlab的方便。matlab直接能对数组进行滤波,只需要传入数据和窗宽就行。python的中值滤波函数对数组的维数要求严格,打个比方你用维数为(200,1)的数组当输入,不行!!!!!!!!!!!!!!必须改成(200,)这样的玩意,它才会给你滤波。
2、paddle安装
想用paddle得去官网找安装指令,不能直接pip install paddle
python -m pip install paddlepaddle-gpu==2.3.1 -i https://mirror.baidu.com/pypi/simple
3、报错信息
报错提示:OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
删除和这个报错提示一同出现的前一个报错提示中的在文件夹D:\Anaconda3\Library\bin文件夹里边的lib****.dll文件即可。
4、图片像素转换
基于Python改变图片像素大小_xiaosakun的博客-CSDN博客_python修改图片像素
5、梯度计算时w=w-k和w-=k的区别。垃圾Python
pytorch报错AttributeError: ‘NoneType‘ object has no attribute ‘zero_‘ - 代码先锋网
6、如果用tensorflow和keras,那版本号必须对应!
这篇知乎的文章有版本对应表
【2022最新】tensorflow和keras版本对应关系 - 知乎文章截图
文章截图
7、图片异常导致无法读取的问题
8、当使用'valid'模式进行padding时,可能会出现负尺寸进而报错。
原因一:
keras的后端是theano,默认channels_first,即他的图像形状是input_shape=(img_channels, img_rows, img_cols )。
而在tensorflow中则是默认channels_last,即input_shape=(img_rows, img_cols, img_channels)。
解决方法:
可添加这两行代码,使其变为channels_last;也可以自行调整输入数据的shape。
from keras import backend as K
K.set_image_dim_ordering("tf")
原因二:
如果padding参数为valid,这意味着将出现卷积过程中发生的自动降维,则可能会得到负尺寸。
解决方法:
将padding的参数替换成same。
9、使用pytorch框架时,验证GPU加速是否可用以及测试展示GPU加速效果
以下代码来自该博客:
pytorch学习笔记2:GPU加速测试,含代码(亲测可用)_跟着小冶一起干的博客-CSDN博客
import torch
import time
from torch import autograd
#GPU加速
print(torch.__version__)
print(torch.cuda.is_available())
a=torch.randn(10000,1000)
b=torch.randn(1000,10000)
print(a)
print(b)
t0=time.time()
c=torch.matmul(a,b)
t1=time.time()
print(a.device,t1-t0,c.norm(2))
device=torch.device('cuda')
print(device)
a=a.to(device)
b=b.to(device)
t0=time.time()
c=torch.matmul(a,b)
t2=time.time()
print(a.device,t2-t0,c.norm(2))
t0=time.time()
c=torch.matmul(a,b)
t2=time.time()
print(a.device,t2-t0,c.norm(2))
10、出现如下报错:
PyTorch:The “freeze_support()” line can be omitted if the program is not going to be frozen
原因:在windows上,子进程会自动import启动它的这个文件,而在import的时候是会自动执行这些语句的。如果不加__main__限制的化,就会无限递归创建子进程,进而报错。所以import的时候使用 name == “main” 保护起来就可以了。
解决办法:
if __name__ == '__main__':
# 代码
11、用pytorch训练时出现如下报错信息:RuntimeError: Found dtype Long but expected Float
原因:此时需要float型数据,但接收过来的数据是long型,故此时需要对输入的参数做一下类型转换
解决方法:
#假设torch_tensor是需要类型转换的张量,其转换为float的代码为:
torch_tensor = torch_tensor.float()
torch_tensor = torch_tensor.float()
12、simulink保存模型框图为图片
Matlab将Simulink模型保存为高清图片_i'm zaker的博客-CSDN博客_matlab simulink模型抓图
13、matplotlib的一些操作
显示图片一段时间后自动关闭
plt.ion()
plt.pause(15) #显示秒数
plt.close()
14、python里边字符串中的花括号
转载自:Python的String字符串使用format函数时带花括号/大括号的操作及使用re时指定变长匹配_独孤尚良dugushangliang的博客-CSDN博客
当字符串使用format函数时,字符串中的花括号则是特殊字符。如果想要输出的字符串也带有花括号怎么办?那就要转义了。