python
LawenceRay
人生自有浮沉,总要迎着有光的地方向上游...
展开
-
字符串类型及操作
字符串:由0个或多个字符组成的有序字符序列,由一对单引号或一对双引号表示;字符串是字符的有序序列,可以对字符进行索引,索引从0计数。由一对三单引号或三双引号可表示多行字符串。字符串有两类共四种表示方法: 如果希望在字符串中包含双引号或单引号:若字符串文本中出现双引号,则字符串两侧则用单引号;若字符串文本中出现单引号,则字符串两侧则用双引号;若字符串中既要出现单引号又要出现双引号,那么在字符串...原创 2018-04-14 14:43:17 · 445 阅读 · 0 评论 -
【Leetcode】Single Number、Single Number II、Single Number III
list操作 time:O(n2);space:O(n)/O(1)time:O(n^2);space:O(n)/O(1)time:O(n2);space:O(n)/O(1)遍历list中的每一个元素,用额外空间记录遍历的数,这个额外空间tmp初始为空,遍历时,若存在,则从tmp中删除,不存在则加入tmp,由于只有一个数只出现了一次,其他数都是两次,所以最后tmp中只剩一个元素,将其输出。...原创 2019-06-19 16:03:16 · 173 阅读 · 0 评论 -
【Leetcode】033. Search in Rotated Sorted Array
问题描述Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a target value to search. If f...原创 2019-06-09 10:37:34 · 99 阅读 · 0 评论 -
【Leetcode】031Next Permutation
问题描述Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest poss...原创 2019-06-09 00:22:36 · 134 阅读 · 0 评论 -
【Leetcode】027. Remove Element
问题描述Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by m...原创 2019-06-08 15:50:17 · 105 阅读 · 0 评论 -
【Leetcode】015ThreeSum
问题描述Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.注意:The solution set must not c...原创 2019-06-02 16:23:56 · 128 阅读 · 0 评论 -
【Leetcode】040Combination Sum
问题描述Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.Each number in candidat...原创 2019-06-13 18:35:07 · 130 阅读 · 0 评论 -
【Leetcode】26. Remove Duplicates from Sorted Array
题目描述Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by m...原创 2019-06-07 00:44:20 · 117 阅读 · 0 评论 -
【Leetcode】039. Combination Sum
题目描述Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.The same ...原创 2019-06-12 23:05:09 · 148 阅读 · 0 评论 -
【Leetcode】011. Container With Most Water
问题描述Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find...原创 2019-06-03 23:27:07 · 134 阅读 · 0 评论 -
【Leetcode】041. First Missing Positive
题目描述Given an unsorted integer array, find the smallest missing positive integer.对于给定的未经排序的array,找出第一个缺失的正整数。例子Input: [1,2,0]Output: 3Input: [3,4,-1,1]Output: 2Input: [7,8,9,11,12]Ou...原创 2019-06-16 01:42:59 · 136 阅读 · 0 评论 -
【图像分割模型coding】Keras 利用Unet进行多类分割
1.前言unet论文地址unet,刚开始被用于医学图像分割。但当时的训练集是黑白图像并且只涉及到二分类问题。此前一直有尝试使用unet处理rgb三彩色图像进行多类分割问题,摸索之后,终有所获。【CPU实现】2.代码实现所采用的数据集是CamVid,图片尺寸均为360*480,训练集367张,校准集101张,测试集233张,共计701张图片。所采用的深度学习框架是tensorflow+ker...原创 2019-07-26 16:30:44 · 17778 阅读 · 291 评论 -
【Leetcode】050 Pow(x, n)
问题描述Implement pow(x, n), which calculates x raised to the power n (xn).用自己的方式实现幂指数函数.实例Input: 2.00000, 10Output: 1024.00000Input: 2.10000, 3Output: 9.26100Input: 2.00000, -2Output: 0.25...原创 2019-06-22 22:51:39 · 169 阅读 · 0 评论 -
【Leetcode】268 Missing Number
题目描述题目含义是,假设有一个长度为n+1的数组(其取值为[0,1,2,...,n]),随机拿掉一个数,使之变为长为n的array,打乱顺序问拿掉的数是几?time:O(nlogn);space:O(1)time:O(nlogn);space:O(1)time:O(nlogn);space:O(1)想法是如果先排序,那么遍历的时候会很容易判断前后两个数是否差值为1。这个好像能补上上...原创 2019-06-17 22:55:55 · 173 阅读 · 0 评论 -
python预处理tif格式图片
RGB彩色图像大家都不陌生,但是什么是真彩色、什么是加彩色呢?[竞赛群里看到别人说真彩色、假彩色,当时完全不懂,碰巧撞上了,记一下]R原色对应TM4波段、G原色对应TM3波段、B原色对应TM2波段,合成得到标准假彩色影像。R原色对应TM3波段、G原色对应TM2波段、B原色对应TM1波段,合成得到真彩色影像。R原色对应TM7波段、G原色对应TM5波段、B原色对应TM2波段,合成得到其它假彩色...原创 2019-06-21 22:40:56 · 8479 阅读 · 0 评论 -
【Leetcode】069Sqrt
题目描述Implement int sqrt(int x).Compute and return the square root of x, where x is guaranteed to be a non-negative integer.Since the return type is an integer, the decimal digits are truncated and ...原创 2019-06-21 22:22:18 · 168 阅读 · 0 评论 -
【Leetcode】074 Search a 2D Matrix
题目描述Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each...原创 2019-06-25 14:29:46 · 179 阅读 · 0 评论 -
【Leetcode】035. Search Insert Position
问题描述Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the arr...原创 2019-06-11 21:19:12 · 125 阅读 · 0 评论 -
【Leetcode】034 Find First and Last Position of Element in Sorted Array
题目描述Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).I...原创 2019-06-10 18:55:08 · 145 阅读 · 0 评论 -
【Leetcode】18. 4Sum
问题描述Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum...原创 2019-06-06 00:06:03 · 130 阅读 · 0 评论 -
【Leetcode】001TwoSum
问题描述:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use th...原创 2019-06-02 15:58:08 · 184 阅读 · 0 评论 -
python爬虫之mac上使用Sequel Pro管理MySQL数据库
最近拿mac做scrapy项目,需要将爬取到的信息存入数据库中,由于之前重装mac,电脑上什么也没有,就连anaconda都是前天才装上的。之前也没在mac上装过mysql,所以也不是很熟练。把学习过程中遇到的各种情况记录下来。一、MySQL安装MySQL的安装比较简单,自行百度mysql for mac 会出现一大堆链接,这里给出其中一个:MySQL for Mac ox 10.12...原创 2018-07-31 16:14:30 · 996 阅读 · 1 评论 -
python爬虫爬取图片
问题:爬取淘宝中某一商品的全部高清图片,并存储到本地。打开淘宝网,比如搜索真丝连衣裙,可以在地址栏中看到第一页的链接如下:https://s.taobao.com/list?spm=a21bo.2017.201867-links-0.23.5af911d9LTKdlG&q=%E7%9C%9F%E4%B8%9D%E8%BF%9E%E8%A1%A3%E8%A3%99&cat=1...原创 2018-07-24 11:16:29 · 5288 阅读 · 0 评论 -
数字类型及操作
基本数据类型一、数字类型及操作:1.整数类型:无限范围及四种进制表示 与数学中整数概念一致,可正可负,没有取值范围限制 四种进制表示形式: 十进制:99,20021 二进制:以0b或者0B开头 八进制:以0o或0O开头 十六进制:以0x或者0X开头2.浮点数类型:浮点数间运算存在不确定尾数,并不是b...原创 2018-04-14 11:08:12 · 909 阅读 · 0 评论 -
python入门
从前总是不敢写自己的博客,怕写出来被人笑话,怕写出来自己觉得别扭,怕自己坚持不下来,可是马上要去读研究生了,自己却迈不出这一步这算怎么回事嘛。我告诉自己从现在开始学一门语言,希望以后有自己为之自豪的作品。'''turtle 库用法:控制画笔绘制状态:pendown() | pd() | down()penup() | pu() | up()pensiz...原创 2018-04-14 08:04:07 · 273 阅读 · 1 评论 -
python入门--正则表达式习题
昨天晚上把正则表达式的知识点梳理了一遍,今天把一些课后习题拿出来记录一下:import re'''如何写一个正则表达式,匹配3位数就有一个逗号的数字?它必须匹配以下数字:'42' '1,234' '6,368,745'但不会匹配:'12,34,567' '1234'这里写的正则表达式肯定算不上精巧,但实实在在可以匹配上述要求第一次写的时候就想直接写出来满足例子的表达式,可...原创 2018-04-18 15:40:57 · 1663 阅读 · 0 评论 -
python入门--正则表达式
问题:假设你有一个无聊的任务,要在很长的文章中,找出所有的电话号码和邮件地址。如果手动翻页,那可能需要很长时间。若果你有一个程序,可以在剪切板的文本中查找电话号码和email地址,那你只用按下cltr+a全选所有文本,然后拷贝到剪切板上,它会用找到的电话号码和email地址替换掉剪切板上的文本。目的:1.从剪切板取得文本2.找出文本中所有的电话号码3.将它们粘贴到剪切板如何做:1.使用pyperc...原创 2018-04-17 22:23:27 · 463 阅读 · 0 评论 -
程序控制
'''score = eval(input())if score >= 90: grade = 'A'elif score >=80: grade ='B'elif score >=70: grade = 'C'elif score>=60: grade = 'D'else: grade = 'X'print("该同学的...原创 2018-04-14 20:54:27 · 277 阅读 · 0 评论 -
python time库
time库包含三类函数:-时间获取:time() ctime() gmtime()-时间格式化:strftime() strptime()-程序计时: sleep() perf_counter()time库的使用:#时间获取time() :获取当前时间戳,即计算机内部时间值,浮点数ctime():获取当前时间并以易读的方式返回gmtime():获取当前时间,表示为计算机可处理的时间格式...原创 2018-04-14 16:19:26 · 2144 阅读 · 0 评论 -
dataframe、series和ndarray的操作
pd.merge合并的时候,首先要求是dataframe对象或者是series对象Can only merge Series or DataFrame objects,a <class 'numpy.ndarray'> was passed这里我的numpy.ndarray是result = model.predict(test_data)返回的结果ndarray如何转dataf...原创 2019-03-19 17:14:02 · 8936 阅读 · 0 评论 -
解决jupyter notebook闪退问题 修改jupyter notebook的默认路径
前段时间,电脑上的anaconda默认升级到了python3.6,一些常用的模块都需要重新安装。除此之外,还有anaconda、jupyter无法打开等问题。最近两天要用到交互式编程工具,所以jupyter的问题需要解决一下。这里我们将其默认路径修改到E盘。*首先在terminal中键入jupyter notebook --generate-config,这个时候会出现以下内容:C:\U...原创 2019-03-17 17:25:15 · 3419 阅读 · 1 评论 -
python合并dataframe对象
每次分析数据过程中,总是会遇到各种问题,一时间想不起来。都说事不过三,这事出了不少次数了,这里还是记下来,但是可能不那么全,记下来也仅仅为了以后本人自己需要。这里声明如下三个dataframe b = np.random.random((3,2)) A = pd.DataFrame(b,columns=['A1','A2']) c = np.random.random((3,2)) ...原创 2019-03-27 00:07:57 · 1078 阅读 · 0 评论 -
python可视化经纬度信息
判断汽车停下:stoped_state = new_data[(new_data['acc_state']==0)&(new_data['gps_speed']==0)]得到了5126个符合条件的点。这样可以用来分析汽车行车过程中经过了哪些点。然后去除掉这些点里面的重复数据:stoped_state.drop_duplicates(inplace=True)然后查看其长度发现问...原创 2019-03-26 23:03:22 · 10257 阅读 · 2 评论 -
pycharm常用快捷键
记一些pycharm的常用操作:ctrl+y删除整行选中某段,control+/注释或着取消注释ctrl+up/down到本页的首尾shift+ctrl+F10运行程序本行首部home,尾部endcontrol+home回到起始代码,control+end到代码块末尾alt+end选择声明尚未声明的模块ctrl+alt+t为选中的代码增加try…catch…ctrl+x剪切某一行...原创 2019-03-29 21:08:26 · 203 阅读 · 0 评论 -
去除嵌套列表中字列表里的空字符
群里有人提问:lists = [ ['主要会计数据', '2017年', '2016年', '本期比上年同期增减(%)', '2015年'], ['营业收入', '62,466,074,604.33', '53,870,447,280.10', '15.96', '57,198,678,035.22'], ['归属于上市公司股东\n的净利润', '648,047,109....原创 2019-03-22 19:55:58 · 557 阅读 · 0 评论 -
时间序列处理
在处理时间序列时,由于秒级别的数据重复率非常高,所以想将秒数据的秒处理掉,只保留分精确度。data['location_time'][1].strftime('%Y-%m-%d %H:%M')遇到这种情况:AttributeError: 'str' object has no attribute 'strftime'在stackoverflow中查询到You should use date...原创 2019-03-26 08:28:40 · 926 阅读 · 0 评论 -
机器学习-积累
正则化:限制参数过多或者过大,避免模型更加复杂。L1 :lasso ,在原损失函数的基础上加上权重参数的绝对值J+λ∥w∥J+\lambda \left \| w \right \|J+λ∥w∥L2:Ridge ,加上权重参数的平方项,所有w的平方项之和为CJ+λ∑jwj2J +\lambda \sum_{j}w_{j}^2J+λ∑jwj2其中λ\lambdaλ是是结构风险最小化的...原创 2019-03-24 23:15:45 · 125 阅读 · 0 评论 -
anaconda navigator无法打开Cannot run solver. No functioning SAT implementations available.
不知道是哪天python环境从python3.6自动升级到了3.7,然后出现一系列问题。但是重新安装python3.7对应的适应包之后,大多能够解决。到目前仅剩的问题是,anaconda navigator无法打开,然后开机需要手动activate base启动conda环境.(base是我的conda环境名。)到现在没有发现于我处一样问题的人。已经将这个问题反馈了,但是好像维护者已经关闭这个is...原创 2019-03-17 19:12:07 · 7884 阅读 · 19 评论 -
分布式并行计算
并发与并行??并发:concurrency并行:parallelism解释一:并行是指两个或多个事件在同一时刻发生;而并发是指两个或多个事件在同一时间间隔发生解释二:并行是在不同实体上的多个事件;并发是在同一实体上的多个事件。解释三:并行是在一台处理器上“同时” 处理多个任务;并发是在多台处理器上同时处理多个任务###同步与异步同步:进程之间的关系不是相互排斥临界资源的关系,而是...原创 2019-03-17 18:40:32 · 3762 阅读 · 0 评论 -
opencv教程
记录以及转给有需要的人http://ex2tron.wang/原创 2019-08-18 21:56:57 · 3579 阅读 · 0 评论