python
ML_BOY
哪怕跑道只剩我一个,我也要跑到终点
展开
-
AttributeError: module cv2.cv2 has no attribute create ThinPlateSplineShapeTransformer 报错
使用opencv-python报错:AttributeError: module 'cv2.cv2' has no attribute 'createThinPlateSplineShapeTransformer'解决方法:pip install opencv-contrib-python原创 2020-05-18 16:47:29 · 3877 阅读 · 0 评论 -
conda 添加虚拟环境中的jupyter 方法
第一步,激活环境: conda activate 环境名(例如我的py36)添加核:python -m ipykernel install --user --name 环境名 --name kernelname (kernel的名字,可以随便取)输入:jupyter notebook就可以看到添加进来的核。...原创 2020-04-14 17:18:42 · 569 阅读 · 0 评论 -
stylegan-v2 报错 error: #error "C++ versions less than C++11 are not supported.
运行stylegan-v2报错:error: #error "C++ versions less than C++11 are not supported.解决方法:打开 dnnlib/tflib/custom_ops.py的 修改第64行:将cmd = 'nvcc ' + opts.strip()改为:cmd = 'nvcc --std=c++11 -DNDEBU...原创 2020-04-10 21:25:04 · 3649 阅读 · 2 评论 -
opencv读取图像或者存储图像时,明明图像存在,但是没读到数据,因为路径中含有中文
在windows上用opencv-python读取图像时,总是没读到数据,明显图像存在,后来发现是因为路径中有中文字符,解决方式是使用numpy兑读取,方式如下:img = cv2.imdecode(np.fromfile(图像路径,dtype=np.uint8),-1)...原创 2020-04-10 15:03:25 · 462 阅读 · 0 评论 -
undefined symbol: __cudaPopCallConfiguration
##undefined symbol: __cudaPopCallConfiguration遇到该问题是因为cuda的版本和pytorch 的cuda版本不一致导致,检测问题的方法:nvcc -V 查看cuda的版本import torchtorch.version.cuda发现上面两个版本不一致,解决方法,去https://pytorch.org/get-started/...原创 2020-01-04 15:56:36 · 6453 阅读 · 7 评论 -
服务器(终端)下载 Google Drive 上面的数据
## 服务器(终端)下载 Google Drive 上面的数据之前在终端下载google drive上的数据都是先下载到本地,再上传,发现太麻烦了,今天找到一种方法分享给大家,可以去github上下载下载的python脚本:https://github.com/chentinghao/download_google_drive/blob/master/download_gdrive.py...原创 2020-01-02 17:45:10 · 8413 阅读 · 6 评论 -
Pandas 中UNIX转年月日格式,提取年月日中的年,月,日
Pandas 中UNIX转年月日格式,提取年月日中的年,月,日 有点久没有写python代码了,对Pandas生疏了很多,今天遇到使用pandas处理时间,就是把UNIX时间格式转化为年月日格式,以及从中把年月日,星期提取出来,查了查文档,遍写成博客。 1 Pandas UNIX转年月日格式def unxi_time(t): t = time.localtime(t) ...原创 2018-04-04 17:56:17 · 4551 阅读 · 0 评论 -
pandas 中上下两行相减(隔行相减) -- shift函数的使用
pandas 中上下两行相减(隔行相减) -- shift函数的使用最近使用pandas处理数据,需求是想相邻两行上下相减,查API发现shift函数,很灵活,。你也可以隔任意行相减。p['xx_1'] = p["xx"].shift(1)上面得到的就是xx字段向下移动一行的结果,和之前相比向下移动一行,你可以设置为任意行,也可是向上向下p['xx'] - p["xx_1"]这就是前后两行的差值,...原创 2018-04-05 09:58:18 · 49822 阅读 · 7 评论 -
pandas 根据某一列排序(sort_values)
pandas 根据某一列排序 pandas排序的方法有很多,sort_values表示根据某一列排序 pd.sort_values("xxx",inplace=True) 表示pd按照xxx这个字段排序,inplace默认为False,如果该值为False,那么原来的pd顺序没变,只是返回的是排序的...原创 2018-04-05 10:19:49 · 154287 阅读 · 7 评论 -
python3下Matplotlib中文显示乱码的问题
python3下Matplotlib中文显示乱码的问题 使用matplotlib绘图时,想要显示中文总是显示不了,解决办法如下,亲测好用:1 linux系统下 1.1 使用如下命令找到中文字体库: fc-list :lang=zh # 找到中文字体库的位置 1.2...原创 2019-05-25 11:12:10 · 898 阅读 · 0 评论 -
Python 读取文件报错:UnicodeEncodeError: 'latin-1' codec can't encode character
#UnicodeEncodeError: 'latin-1' codec can't encode character例如:file = open("xxx.txt","r",encoding="utf-8")for line in file: print(line)UnicodeEncodeError: 'latin-1' codec can't encode cha...原创 2019-07-13 10:14:31 · 25774 阅读 · 0 评论 -
pycharm 出现输入backspace无法删除程序
##pycharm 出现输入backspace无法删除程序Tool --> vim Emulator (讲√取消即可)原创 2019-07-11 09:34:11 · 1668 阅读 · 2 评论 -
python 使用argparse 输入分割符时,例如\t,无法分割字符
##python 使用argparse 输入分割符时,例如\t,无法分割字符在使用python 使用argparse,得到参数,比如分割字符串,你想输入"\t",当时输入\t是发现无法分割,这个时候,需要改一下:arg.separator 表示的是你输入的\tsep = arg.separator.encode('utf-8').decode('unicode_escape')...原创 2019-07-15 15:59:33 · 2248 阅读 · 2 评论 -
Python 字符分割时,只分割最后一个(rsplit的使用)
##Python 字符分割时,只分割最后一个(rsplit的使用)在python分割时,有时候不是把整个字符分割,而是只分割部分,例如:我要分割文件路径,只想把最后的文件名去除,保留文件夹的路径。例如:/home/username/data/text.txt 我想要得到/home/username/data/。如果用split则会把整个分割成一个list,但是可以使用rsplit。例如...原创 2019-07-16 12:03:05 · 46586 阅读 · 5 评论 -
Ubuntu 下google chrome 打开jupyter notebook 报错ERROR:browser_gpu_channel_host_factory.cc(120)] Failed to
Ubuntu 下google chrome 打开jupyter notebook 报错ERROR:browser_gpu_channel_host_factory.cc(120)] Failed to launch GPU process报这种错,把export BROWSER=google-chrome 添加到配置文件,比如 sudo vim /etc/profile或者添加到r.bashrc...原创 2018-04-03 08:25:06 · 3015 阅读 · 0 评论 -
tensorflow 中tile函数用法讲解
tensorflow中tile是用来复制tensor的指定维度,具体看下面的代码:import tensorflow as tfa = tf.constant([[1, 2], [3, 4], [5, 6]], dtype=tf.float32)a1 = tf.tile(a, [2, 2])with tf.Session() as sess: print(sess.run(a1)...原创 2018-03-24 20:22:05 · 5851 阅读 · 0 评论 -
numpy中transpose和swapaxes函数讲解
transpose和swapaxes函数讲解transpose() 这个函数如果括号内不带参数,就相当于转置,和.T效果一样,而今天主要来讲解其带参数。 我们看如下一个numpy的数组: `arr=np.arange(16).reshape((2,2,4)) arr= array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7]], [[ 8原创 2017-04-23 19:34:53 · 50906 阅读 · 14 评论 -
快速学会pandas中Dataframe索引.ix,.iloc,.loc的使用以及区别
pandas中索引的使用定义一个pandas的DataFrame对像import pandas as pddata = pd.DataFrame({'A':[1,2,3],'B':[4,5,6],'C':[7,8,9]},index=["a","b","c"])data A B Ca 1 4 7b 2 5 8c 3 6 9.loc 的使用原创 2017-08-25 23:33:12 · 83110 阅读 · 6 评论 -
Python中列表的索引的一个特殊用法
Python中列表索引特殊用法x=[1,2,3,5,6,7,8,9]x[1:1000000]x [22222,66666]res:[1, 2, 3, 5, 6, 7, 8, 9][]首先是定义了一个列表,x=[1,2,3,5,6,7,8,9], 然后输入x[1:1000000],开始我以为会报索引越界的错误,可是没有,而结果是[2,3,5,6,7,8,9],如果输入x [22222,66666原创 2017-09-28 21:02:32 · 2638 阅读 · 0 评论 -
Anaconda环境的创建/激活/删除/管理
Anaconda环境的创建 conda create -n py3 python=3.5其中py3表示创建环境的名字,后面python=3.5表示创建的版本。conda create -n py3 python=3.5 numpy pandas这个是在创建环境的时候同时安装包Anaconda环境的激活在 OSX/Linux 上source activate py3py3为环境名,上述表示激活py3w原创 2017-10-09 14:43:29 · 90161 阅读 · 0 评论 -
Python中数组,列表:冒号的灵活用法(np数组,列表倒序)
Python中数组,列表:冒号的灵活用法(np数组,列表倒序)让我们来看一个例子:import numpy as npx=np.array([[1,2,3],[5,6,7],[7,8,9]])print(x)Out[64]:array([[1, 2, 3], [5, 6, 7], [7, 8, 9]])以上的结果我想大家应该没问题把,就是定义了一个np数组,关键在下原创 2017-10-01 22:43:46 · 25755 阅读 · 5 评论 -
Numpy 中clip函数的使用
Numpy 中clip函数的使用numpy.clip(a, a_min, a_max, out=None)[source]其中a是一个数组,后面两个参数分别表示最小和最大值,怎么用呢,老规矩,我们看代码:import numpy as npx=np.array([1,2,3,5,6,7,8,9])np.clip(x,3,8)Out[88]:array([3, 3, 3, 5, 6, 7, 8原创 2017-10-02 10:56:32 · 143977 阅读 · 7 评论 -
将图片保存为h5py文件
将图片存为h5py文件直接看代码比较清晰from scipy import miscX = misc.imresize(misc.imread('xx.jpg' % i), image_size)h = h5py.File('pic.h5')h.create_dataset("picture",data=X)该段代码第一句是导入scipy,注意使用scipy的misc需要安装PIL,不然会报错原创 2017-10-03 20:57:31 · 6268 阅读 · 4 评论 -
linux下Anaconda的安装
linux下Anaconda的安装Anaconda的下载Anaconda点击下载 选择自己需要的版本,此处我用的是python3.6的,也就是左边那个,点击下载就可以。 下载好了以后就开始安装,此处我用的是centos7,ubuntu也是一样的。Anaconda安装找到自己下载的目录,我的是下载在home下cd /home #切换目录到你下载的地方,此处我下载在home下输入bash Ana原创 2017-10-11 11:09:25 · 62291 阅读 · 3 评论 -
Python 中dict字典get方法讲解
Python 中dict字典get方法讲解python中字典的get方法比较简单,我们看一段代码:x={'a':1,'b':2,'c':3}print(x.get('a',6))print(x.get(6,'a'))print(x.get(1,6))print(x.get(2,'a'))print(x.get(6))print(x.get('a'))1 a 6 a None 1原创 2017-10-23 22:43:53 · 3348 阅读 · 0 评论 -
Python 中 optparse模块简介
Python 中 optparse模块主要是方便我们像在终端一样输入命令,具体的使用方法我们看如下的代码:from optparse import OptionParseroptParser = OptionParser()optParser.add_option('-n','--number',action='store',type='int',dest='int_number')optio原创 2017-11-03 23:28:15 · 655 阅读 · 0 评论 -
Python 中pandas读取文件Initializing from file failed
pandas读取文件报如下的错误:--------------------------------------------------------------------------OSError Traceback (most recent call last)<ipython-input-21-f8680ec116e3> in原创 2017-11-13 21:01:44 · 105654 阅读 · 25 评论 -
numpy 中pad讲解
numpy 中np.pad的用法pad(array, pad_width, mode, **kwargs) 1、其中array代表需要填充的代码 2、pad_width 表示每个维度左右两边填充的数量,mode表示填充模式,可以是等值填充,常数填充等, 具体我们看一个例子:x=np.arange(8).reshape(2,2,2)k = np.pad(x,pad_width=((2,3),(原创 2017-12-08 19:53:07 · 4178 阅读 · 0 评论 -
tensorflow 中tf.gather(params, indices, validate_indices=None, name=None) 函数讲解
tf.gathertf.gather(params, indices, validate_indices=None, name=None, axis=0)params 表示你输入的张量,indices表示你想要params张量中切片的维度,所以这个函数就是挑选出params中indices对应的数。举例子x = tf.constant(np.arange(8).reshape((2,2,2)))y原创 2017-12-09 16:35:54 · 1565 阅读 · 0 评论 -
window下安装Anaconda
本人用的是win7安装的,具体方法见以下anaconda安装比较简单Anaconda下载网址 我选择的是python3.6,也就是左边的 下载文件后,点击运行: 点击next点击 I Agree选择ALL Users ,点击next选择安装路径,并点击next这个地方全部勾选,全部选择,点击install,等待安装,可能需要几分钟完成安装安装成功后,在开始菜单就可以看到:然后就可以开始P原创 2017-12-29 16:09:48 · 883 阅读 · 0 评论 -
pandas入门(一)
pandas入门之Series(一)from pandas import Seriesobj=Series([4,7,-5,3]) #创建Series对象,使用默认索引(默认索引是从0开始的数字)obj运行结果: 0 4 1 7 2 -5 3 3 dtype: int64obj=Series((4,7,-5,3)) #不仅可以把列表转换成Series对象,也可原创 2017-05-03 10:19:59 · 2065 阅读 · 0 评论