python
miahhrgbfcyur
这个作者很懒,什么都没留下…
展开
-
k-means算法实现python
import numpy as npimport matplotlib.pyplot as plt# 两点距离def distance(e1, e2): return np.sqrt((e1[0]-e2[0])**2+(e1[1]-e2[1])**2)# 集合中心def means(arr): return np.array([np.mean([e[0] for e in arr]), np.mean([e[1] for e in arr])])# arr中距离a最远的元素转载 2020-05-22 22:55:21 · 281 阅读 · 0 评论 -
利用request库请求api
import requestsdef re(): url = 'http://shuyantech.com/api/entitylinking/cutsegment?q=' word = '打球的李娜和唱歌的李娜不是同一个人' url = url + word r = requests.get(url) print(r.text)if __name__ == "__main__": count = 0 while(True):原创 2020-05-13 13:25:50 · 217 阅读 · 0 评论 -
《python编程:从入门到实践》课后习题答案
https://www.xz577.com/j/129.html原创 2020-01-10 21:18:31 · 7629 阅读 · 0 评论 -
python和c++的区别
https://www.jianshu.com/p/c70474e1db0a原创 2020-01-10 20:26:46 · 139 阅读 · 0 评论 -
深入理解计算机系统
leal和mov的用法:https://blog.csdn.net/farmwang/article/details/75103220原创 2019-12-11 20:21:32 · 120 阅读 · 0 评论 -
leetcode 1202 python
题目要求:https://leetcode-cn.com/problems/smallest-string-with-swaps/class Solution: def smallestStringWithSwaps(self, s: str, pairs: List[List[int]]) -> str: p = {i:i for i in range(len(...原创 2019-12-11 20:10:25 · 135 阅读 · 0 评论 -
leetcode 200 python
题目要求:https://leetcode-cn.com/problems/number-of-islands/class Solution: def numIslands(self, grid: List[List[str]]) -> int: if not grid: return 0 row = len(grid) col =...原创 2019-12-11 19:03:57 · 206 阅读 · 0 评论 -
leetcode 130 python
题目要求:https://leetcode-cn.com/problems/surrounded-regions/class Solution: def solve(self, board: List[List[str]]) -> None: """ Do not return anything, modify board in-place ins...原创 2019-12-11 18:51:53 · 187 阅读 · 0 评论 -
leetcode 128 python
class Solution: def longestConsecutive(self, nums: List[int]) -> int: if not nums: return 0 nums.sort() longest_streak = 1 current_streak = 1 ...原创 2019-12-11 15:00:45 · 214 阅读 · 0 评论 -
leetcode 1025 python
题目要求:https://leetcode-cn.com/problems/divisor-game/思路:如果N是奇数,因为奇数的所有因数都是奇数,因此 N 进行一次 N-x 的操作结果一定是偶数,所以如果 a 拿到了一个奇数,那么轮到 b 的时候,b拿到的肯定是偶数,这个时候 b 只要进行 -1, 还给 a 一个奇数,那么这样子b就会一直拿到偶数,到最后b一定会拿到最小偶数2,a就输了。...原创 2019-12-09 19:38:33 · 123 阅读 · 0 评论 -
mac下安装plotly
conda install plotly原创 2019-12-04 11:31:31 · 825 阅读 · 2 评论 -
leetcode 746 python 动态规划
题目要求:https://leetcode-cn.com/problems/min-cost-climbing-stairs/class Solution: def minCostClimbingStairs(self, cost: List[int]) -> int: if len(cost) == 0: return 0 ...原创 2019-11-29 15:02:28 · 152 阅读 · 0 评论 -
python查找元素的下标 leetcode 392
a_list.index(‘a’) //返回a在列表中每一次出现的位置,默认搜索整个列表a_list.index(‘a’,0,3) //返回a在指定切片内第一次出现的位置题目要求:https://leetcode-cn.com/problems/is-subsequence/class Solution: def isSubsequence(self, s: str, t: str...原创 2019-11-29 14:41:30 · 203 阅读 · 0 评论 -
overflow encountered in ubyte_scalars像素加减运算溢出异常
https://blog.csdn.net/Acecai01/article/details/80248139原创 2019-11-25 16:37:56 · 3392 阅读 · 0 评论 -
数据统计
Result_final_1 : 第一行result_final_2: 第二行(下同)result_3: 第3到10行result_4: 第11到20 行result_5 :第21到30行result_6: 31-407: 41-508: 51-60原创 2019-11-20 15:24:44 · 114 阅读 · 0 评论 -
python文件读取每一行操作
https://blog.csdn.net/wsLJQian/article/details/81210867原创 2019-11-24 21:40:32 · 1459 阅读 · 0 评论 -
python+opencv中imread函数第二个参数的含义
= 0: 灰度图0:三通道彩色图<0:原图,带alpha通道原创 2019-11-20 21:18:16 · 1563 阅读 · 0 评论 -
python opencv 灰度图转换和resize函数的使用
import cv2import numpy as npimg1 = cv2.imread('left.png',1)img1 = cv2.resize(img1, (797,1212))dst1 = cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)cv2.imwrite('l.png',dst1)img1 = cv2.imread('left.png',1...原创 2019-11-20 20:54:18 · 1872 阅读 · 0 评论 -
视差统计
import cv2import numpy as npimport csvimport pandas as pdl = []lena = cv2.imread('shicha.png',0) # 读取和代码处于同一目录下的 lena.pngfor i in range(0, 797): for j in range(0, 1212): if lena[i, ...原创 2019-11-20 15:44:50 · 160 阅读 · 0 评论 -
python读取txt文件的前几行
法一:f = open("result_final_7.txt","r") #设置文件对象for i in range(5): print(f.readline().strip())原创 2019-11-20 15:19:21 · 12987 阅读 · 1 评论 -
leetcode 303 python(动态规划)
题目要求:https://leetcode-cn.com/problems/range-sum-query-immutable/class NumArray: def __init__(self, nums: List[int]): self.dp = nums[:] # self.dp[i]存储0~i的子序列和 fo...原创 2019-11-18 19:25:48 · 220 阅读 · 0 评论 -
leetcode 198 python
题目要求:https://leetcode-cn.com/problems/house-robber/class Solution: def rob(self, nums: List[int]) -> int: if not nums: return 0 if len(nums) == 1: retu...原创 2019-11-18 16:24:20 · 192 阅读 · 0 评论 -
leetcode 121 python(动态规划)
题目要求:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/class Solution: def maxProfit(self, prices: List[int]) -> int: if not prices: return 0 dp = [...原创 2019-11-18 16:16:18 · 232 阅读 · 0 评论 -
leetcode 70 python (动态规划)
题目要求:https://leetcode-cn.com/problems/climbing-stairs/class Solution: def climbStairs(self, n: int) -> int: if n == 1: return 1 if n == 2: return 2 ...原创 2019-11-17 22:36:42 · 151 阅读 · 0 评论 -
leetcode 53 python 动态规划
题目要求:https://leetcode-cn.com/problems/maximum-subarray/弄一个数组,dp[i]存到当前位置结束时最大的前缀和。class Solution: def maxSubArray(self, nums: List[int]) -> int: if not nums: return 0 ...原创 2019-11-17 21:43:25 · 81 阅读 · 0 评论 -
leetcode 315 python
题目要求:https://leetcode-cn.com/problems/count-of-smaller-numbers-after-self/python列表insert的操作:https://www.iplaypy.com/jinjie/list-insert.htmlpython内置函数binect的用法:https://www.cnblogs.com/skydesign/ar...原创 2019-11-16 22:31:20 · 244 阅读 · 0 评论 -
leetcode 179 python
题目要求:https://leetcode-cn.com/problems/largest-number/python中map函数的用法:https://www.runoob.com/python/python-func-map.htmlpython中lstrip和rstrip的用法:https://blog.csdn.net/csdn15698845876/article/detail...原创 2019-11-16 20:23:05 · 198 阅读 · 0 评论 -
leetcode 151 python
题目要求:https://leetcode-cn.com/problems/reverse-words-in-a-string/split()当不带参数时以空格进行分割(不管几个空格全部砍掉),当代参数时,以该参数进行分割。python 字符串(str)和列表(list)的互相转换:https://blog.csdn.net/roytao2/article/details/534333...原创 2019-11-16 16:14:00 · 325 阅读 · 0 评论 -
leetcode 646 python
题目要求:https://leetcode-cn.com/problems/maximum-length-of-pair-chain/思路:很简单的贪心class Solution: def findLongestChain(self, pairs: List[List[int]]) -> int: pairs.sort(key=lambda x: x[1])...原创 2019-11-16 15:55:20 · 130 阅读 · 0 评论 -
leetcode 241 python
题目要求:https://leetcode-cn.com/problems/different-ways-to-add-parentheses/思路:分治法,递归def diffWaysToCompute(input): # 如果只有数字,直接返回 if input.isdigit(): return [int(input)] ...原创 2019-11-16 15:41:55 · 203 阅读 · 0 评论 -
图像分割的评测指标
coefficient原创 2019-11-15 19:35:24 · 741 阅读 · 0 评论 -
leetcode 42 python
题目要求:https://leetcode-cn.com/problems/trapping-rain-water/看到的一个大佬思路,实在是太有意思了!class Solution(object): def trap(self, height): """ :type height: List[int] :rtype: int ...原创 2019-11-15 15:13:43 · 115 阅读 · 0 评论 -
leetcode 45 python
题目要求:https://leetcode-cn.com/problems/jump-game-ii/原创 2019-11-13 21:38:30 · 155 阅读 · 0 评论 -
leetcode 61 python
题目要求:https://leetcode-cn.com/problems/rotate-list/原创 2019-11-13 21:07:18 · 237 阅读 · 0 评论 -
leetcode 76 python
题目要求:https://leetcode-cn.com/problems/minimum-window-substring/思路:滑动窗口原创 2019-11-13 20:08:07 · 117 阅读 · 0 评论 -
leetcode 81 python
题目要求:https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/原创 2019-11-13 19:52:58 · 154 阅读 · 0 评论 -
leetcode 85 python
题目要求:https://leetcode-cn.com/problems/maximal-rectangle/思路:https://blog.csdn.net/u014626513/article/details/81381948原创 2019-11-13 19:38:46 · 161 阅读 · 0 评论 -
leetcode 84 python
题目要求:https://leetcode-cn.com/problems/largest-rectangle-in-histogram/思路:https://blog.csdn.net/qq_17550379/article/details/85093224原创 2019-11-13 19:26:17 · 260 阅读 · 0 评论 -
leetcode 65 python
题目要求:https://leetcode-cn.com/problems/valid-number/原创 2019-11-13 17:23:05 · 113 阅读 · 0 评论 -
leetcode 95 python
题目要求:https://leetcode-cn.com/problems/unique-binary-search-trees-ii/comments/原创 2019-11-13 16:42:27 · 120 阅读 · 0 评论