![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
文章平均质量分 94
AI无昵称
计算机视觉小虾;
学了好多用不上;
深度学习;
看看电影;
饭后要遛食;
Be strong!
展开
-
Numpy array数组reshape易错点解析
X.reshape(a, b, c)是按照从后向前的顺序重新组合元素,从而塑造数组X形状的。原创 2020-07-14 22:45:02 · 719 阅读 · 0 评论 -
python logging日志模块使用
实例选自:openpifpaf/log.py参考:博客1博客2import loggingLOG = logging.getLogger(__name__)def configure(args): # pylint: disable=import-outside-toplevel from pythonjsonlogger import jsonlogger ...原创 2020-03-09 12:06:05 · 606 阅读 · 0 评论 -
python class __init__() 外部定义属性
举例说明,比如定义一个PifPaf类如下class PifPaf(object): force_complete = True connection_method = 'blend' fixed_b = None pif_fixed_scale = None paf_th = 0.1 def __init__(self, stride): ...原创 2020-02-21 21:06:06 · 3473 阅读 · 0 评论 -
pip install, python setup.py, egg-info的说明--以Nvidia Apex安装为例
Install Nvidia Apex若第一次安装需要把项目从github克隆到本地Clean the old install before rebuilding:pip uninstall apexcd apex_repo_dirrm -rf build (if present)rm -rf apex.egg-info (if present)Install package:...原创 2020-02-12 19:03:56 · 7153 阅读 · 1 评论 -
numpy array 以及pytorch tensor 的索引(切片索引,整型索引)
我们知道,在python中,变量的赋值‘=’其实是对原始变量的引用,是一种绑定。因此有时我们为了创建新的变量而不影响原始数据,需要使用拷贝(copy),这也是赋值和拷贝的不同。numpy中的索引有切片索引(slice array indexing)和整型索引(integer array indxing)其中,numpy array中的切片索引(slice)是对原始数组的一个view,会影响...原创 2018-08-02 09:19:44 · 1023 阅读 · 0 评论 -
reshape, transpose, resize的区别
numpy.reshape takes a shape as input, and format array into that shape. An intuitive way to think of it is that Numpy flattens your array into a plain list, and truncate the long flattened list into t...原创 2018-08-28 15:14:31 · 979 阅读 · 0 评论 -
python中attribute(特性)和property(属性)的区别
property 是特殊的 attribute,详细讨论:https://www.zhihu.com/question/40015172转载 2018-10-31 10:37:41 · 7190 阅读 · 0 评论 -
__setattr__, __getattr__, __getattribute__, _ getitem_的用法和区别
一、类实例属性的获取与设置转载自转载自1. __getattribute__程序每次访问对象属性时,Python系统都会调用这个特殊的方法,即使属性字典里面已经有了改属性,也依然会触发__getattribute__。__getattribute__方法下应该避免使用self.attr访问属性,否则会出现无限递归。如要要访问实例属性,应该直接通过super()来做。2....原创 2018-12-03 20:50:07 · 1887 阅读 · 0 评论 -
python中的 type hint 类型提示
许多IDE(如pycharm)会有输入类型提示和自动代码补全,就是靠类似于静态语言中的变量类型声明的做法。python语言是动态的,所以不存在需要使用重载功能,python中的重载只是为了类型提示和参数数目提示。1. 使用overload或者typing.TypeVar(后者要求固定参数数目)使用overload可以提示同一个名字的函数(方法)支持的不同类型和数目的形参。使用typin...原创 2018-12-22 10:51:11 · 9534 阅读 · 0 评论 -
mac上安装python3.6 设置虚拟环境
使用home brew进行mac系统上的各种包的管理比较方便。使用brew安装pytho3和方便地进行不同版本python直接的切换。1. 使用home brew 安装 python3.6转载自mac系统会自带python,一般是python2.6或python2.7。但是你可能需要用到python3.x,所以需要自己在mac系统中安装python。推荐采用homebrew安装pytho...原创 2018-12-17 19:49:23 · 5547 阅读 · 0 评论 -
ubuntu安装HDF5 1.10.4 以及对应的python hdf5包
1.安装HDF5 1.10以及对应的python hdf5的包 (HDF5 1.10.4安装具体可参考其他博客)2. 使用命令行环境变量安装对应的python hdf5包,HDF5_DIR=/usr/local/hdf5 pip install h5py系统内安装有其他HDF5版本,比如1.8.16,为了使用新安装的版本所以添加环境变量制定使用的HDF5版本(参考:https:/...原创 2019-02-22 10:27:56 · 4279 阅读 · 0 评论 -
Python, NumPy, Pytorch中的多进程中 每个进程的随机化种子 误区
python自带的random在不同子进程中会生成不同的种子,而numpy.random不同子进程会fork相同的主进程中的种子。pytorch中的Dataloader类的__getitem__()会在不同子进程中发生不同的torch.seed(),并且种子与多进程的worker id有关(查看worker_init_fn参数说明)。但是三者互不影响,必须独立地处理。因此在写自己的数据准备代码时,...原创 2019-07-22 17:03:16 · 1146 阅读 · 0 评论 -
python中的 += 操作是 in-place,会覆盖原始内存
You avoid the in-place by doingout = out + residualYou can verify that with other data structures as well:a = []b = a # b is the same as aa += [5]print(b) # prints [5]# nowa = []b = a...转载 2019-04-02 10:45:45 · 724 阅读 · 0 评论 -
python中的函数必须在调用之前(函数调用函数例外)定义
转载自标准的先函数定义,后函数调用def add1(a,b): return a+bprint add1(1,2)函数2可以调用后面定义的函数3#事实上,我们在调用函数2的时候,一样是遵循先定义后调用的准则def add2(a,b): return add3(a,b)def add3(a,b): return a+b print add2(1,2)...转载 2019-04-03 14:58:27 · 6054 阅读 · 0 评论 -
python中常用的装饰器
cython中常见的函数装饰器@cython.boundscheck(False) # Cython默认进行数组越界检查,这也是个降低速度的地方,不过可以用@cython.boundscheck(False)的方法关闭该功能@cython.wraparound(False) # @cython.wraparound(False) 消除了相对数组尾部的负数下标的处理(类似Python列表)#...原创 2019-07-18 15:53:12 · 519 阅读 · 0 评论 -
判断平面内一个点 是否在两个点所确定的长轴椭圆内
# 点到两个端点所确定的直线的距离 classic formula is: # # d = [(x2-x1)*(y1-y)-(x1-x)*(y2-y1)] / sqrt((x2-x1)**2 + (y2-y1)**2) # xD = (x2 - x1) yD = (y2 - y1) detaX = x1 - X detaY = y1 - Y...原创 2018-04-25 15:54:18 · 2221 阅读 · 0 评论 -
python中的多进程与多线程 提升keras训练时数据准备的速度
更新可以参考如下博客:使用keras.utili中的Sequencehttps://stanford.edu/~shervine/blog/keras-how-to-generate-data-on-the-fly 1. 测试状态下,如果用predict函数,则模型会重新编译加载,可以使用中间层输出,来计算真正的测试阶段前向传播所用的时间。点击打开链接2. 训练状态下,GP...原创 2018-04-22 10:45:29 · 10899 阅读 · 0 评论 -
python全局变量
python中global关键字主要作用是声明变量的作用域。在C语言中,由于变量一定是先声明,后使用,所以我们可以清楚的知道,现在使用的变量是全局还是局部,比如:[cpp] view plain copyint a = 5; void test(void) { a = 1; // 没有先声明,所以用的是全局的变量a } void test1(void) { i...转载 2018-04-09 19:23:15 · 422 阅读 · 0 评论 -
Failed to import pydot
Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.的解决办法报错时提示没有pydot和graphviz模块,但是在安装的时候需要注意安装模块的位置, 如果使用的是虚拟环境下, 后者的模块要安装在系统的默认环境中使用以下两条语句进行安装pip insta原创 2017-03-12 16:27:51 · 2165 阅读 · 0 评论 -
Python中的 args,**kwargs,命名关键字参数
转载自:http://www.cnblogs.com/fengmk2/archive/2008/04/21/1163766.html先来看个例子:def foo(*args, **kwargs): print 'args = ', args print 'kwargs = ', kwargs print '--------------------------...原创 2017-03-29 08:51:47 · 885 阅读 · 0 评论 -
MoviePy 数据动态可视化 图像转动态图或者视频
转载自: http://zulko.github.io/blog/2014/11/29/data-animations-with-python-and-moviepy/Data Animations With Python and MoviePyNov 29th, 2014 | Comments Python has some great data visua转载 2017-07-20 15:33:08 · 9881 阅读 · 0 评论 -
python 数据读入 常用的 程序 段落
1. hdf5文件的创建与载入try: with h5py.File('X.h5') as hf: X, Y = hf['imgs'][:], hf['labels'][:] print("Loaded images from X.h5") except (IOError,OSError, KeyError): print("Erro...原创 2017-05-28 20:57:48 · 1969 阅读 · 0 评论 -
python @ @classmethod @staticmethod @property
转载自http://www.cnblogs.com/elie/p/5876210.htmlhttp://www.360doc.com/content/14/0811/11/16044571_400987060.shtml1.python中@classmethod @staticmethod区别Python中3种方式定义类方法, 常规方式, @classmethod修饰方式, @...原创 2017-05-06 14:15:34 · 668 阅读 · 0 评论 -
python super().__init()__
class Root(object): def __init__(self): print 'ok, good luck!' class A(Root): def __init__(self): super(A, self).__init__()class B(A): def __init__(se原创 2017-12-15 16:38:03 · 10090 阅读 · 0 评论 -
python 矢量化计算
列表推导式比循环更快事实上,标准Python中有比for循环更快的方案:使用列表推导式。但是列表推导式将产生一个新的列表,而不是直接修改原来列表中的元素。下面的语句执行时,将计算出一个新的列表保存每个正弦值:>>> x = [math.sin(t) for t in x]np.sin同样也支持计算单个数值的正弦值。不过值得注意的是,对单个数值的计算math原创 2018-01-12 09:50:57 · 5674 阅读 · 0 评论 -
numpy array数组拷贝
1. 数组拷贝 Copy of matrixWhen you do operations on an array, then you have to be careful whether or not the array is copied or only referenced to. When you change something in the copied array, then yo原创 2018-01-22 11:19:33 · 467 阅读 · 0 评论 -
Ubuntu16.04 安装 python3.6
安装python3.6参考 点击打开链接1. 添加源sudo add-apt-repository ppa:jonathonf/python-3.62. 安装sudo apt-get updatesudo apt-get install python3.63. 在虚拟环境下搭建以python3.6为解释器的工作环境virtualenv -p /usr/bin/p...原创 2018-01-26 22:03:19 · 5870 阅读 · 0 评论 -
matplotlib 画图
1. 画曲线图Tompson = np.array([0, 0, 0, 0, 0.011, 0.051, 0.15, 0.251, 0.35, 0.44, 0.51, 0.59, 0.65, 0.68, 0.725, 0.752, 0.8])ours = np.array([0.00000000e+00, 1.21182744e-04, 4.26563257e-02,原创 2017-09-06 14:57:31 · 869 阅读 · 0 评论 -
python中的变量赋值,浅拷贝,深拷贝
转载地址: http://www.cnblogs.com/Eva-J/p/5534037.html初学编程的小伙伴都会对于深浅拷贝的用法有些疑问,今天我们就结合python变量存储的特性从内存的角度来谈一谈赋值和深浅拷贝~~~预备知识一——python的变量及其存储 在详细的了解python中赋值、copy和deepcopy之前,我们还是要花一点时间来了解一转载 2017-01-12 15:53:45 · 6070 阅读 · 2 评论 -
python 图像读入 reshape尺寸时的问题
可以用matplotlib模块中的image模块进行图像的读取#coding=utf-8import matplotlib.pyplot as pltimport matplotlib.image as mimageimage=mimage.imread('lala.jpg')print image.shape# show a pictureimage=image.res原创 2017-01-09 20:28:42 · 17413 阅读 · 1 评论 -
windows下python的第三方包 numpy scipy matplotlib 简便安装
网上有不少版本的安装方法,但是有一些因为每个人的电脑环境不一样,因此别人可以成功的方法到自己这里就不一定可行了。下面介绍一下自己踩过很多坑之后发现的最方便有效无脑的安装办法。可以帮助你跳过很多未知的潜在的坑啊!注意安装包安装的顺序:numpy—>scipy—>matplotlib,因为最后一个包的安装需要依赖之前的包,这是必须要注意的问题1.搜索一下需要用的对应版本的num原创 2016-11-30 09:39:08 · 810 阅读 · 0 评论 -
python __getattr__ 和 __setattr__方法、属性私有化
Python setattr() 函数描述语法setattr 函数对应函数 getatt(),用于设置属性值,该属性必须存在。setattr 语法:setattr(object, name, value)参数object -- 对象。name -- 字符串,对象属性。value -- 属性值。返回值实例转载 2018-02-07 14:53:16 · 1053 阅读 · 0 评论 -
python中环境变量,默认路径设置
转载自:http://www.tuicool.com/articles/EB3miqrsys模块包含了与python解释器和它的环境有关的函数,这个你可以通过dir(sys)来查看他里面的方法和成员属性。下面的两个方法可以将模块路径加到当前模块扫描的路径里:sys.path.append('你的模块的名称')。sys.path.insert(0,'模块的名称转载 2017-02-27 18:51:10 · 10495 阅读 · 0 评论