python
文章平均质量分 57
forever_zzx
这个作者很懒,什么都没留下…
展开
-
pandas学习记录
目录前言二、使用步骤1. pandas数据结构1.1 Series1.2 DataFrame2. 使用方法2.1 创建对象2.2 查看数据总结前言提示:这里可以添加本文要记录的大概内容:例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。一、pandas是什么?Pandas是一个强大的分析结构化数据的工具集;它的使用基础是Numpy(提供高性能的矩阵运算);用于数据..原创 2021-04-20 23:59:36 · 318 阅读 · 0 评论 -
Jupyter 添加Conda环境
进入某个环境,安装相关包安装ipykernelconda install -c anaconda ipykernel将环境添加到jupyter lab中python -m ipykernel install --user --name=myEnv启动jupyter, 在.ipynb文件中就能看到添加的环境原创 2021-02-23 10:21:33 · 157 阅读 · 0 评论 -
pytorch安装及faster-rcnn.pytorch使用记录
目前所处的办公环境限制较多,对搭建开发环境造成较大阻碍,在安装pytorch时, pip和conda库不能及时更新,很多时候需要手动安装。在这样的背景下,本文记录pytorch和faster-rcnn.pytorch 的在使用过程中的问题。1. pytorch的安装pytorch的安装首先需要确定安装的版本,其次要明确当前cuda的版本,最后还要知道所使用的python版本。一般来讲,如果使用官方库安装,安装的pytorch应该是在对应版本的cuda下编译的,但是由于本人所处的环境,pip和conda库原创 2020-10-13 11:21:45 · 327 阅读 · 1 评论 -
torchvision transform巨坑
最近用到torchvision.transform.Normalize,发现不同版本对输入的改变不同,下面对比torchvision 0.2.1和0.4.2版本0.2.1:def normalize(tensor, mean, std): """Normalize a tensor image with mean and standard deviation. See ``Normalize`` for more details. Args: tensor (Te原创 2020-08-24 15:28:39 · 646 阅读 · 0 评论 -
mmcv 安装记录
安装mmcv,我选择的是源码安装,按照官方给出的步骤,运行命令MMCV_WITH_OPS=1 pip install -e .出现错误提示,如下:distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse(‘pytest-runner’)于是安装pytest-runner:pip install pytest-runner随后再次运行安装命令,仍然出现错误,于是原创 2020-07-18 14:55:55 · 5892 阅读 · 11 评论 -
LeetCode124 最大路径和
给定一个非空二叉树,返回其最大路径和。本题中,路径被定义为一条从树中任意节点出发,达到任意节点的序列。该路径至少包含一个节点,且不一定经过根节点。示例 1:输入: [1,2,3] 1 / \ 2 3输出: 6示例2:输入: [-10,9,20,null,null,15,7] -10/ \9 20/ ...原创 2019-10-19 22:13:24 · 142 阅读 · 0 评论 -
两数相加,不用加减乘除
写一个函数,求两个整数之和,要求在函数体内不得使用+、-、*、/四则运算符号。相加从二进制的角度理解:和为异或结果,如果与运算结果左移为0则输出结果,否则相加的和和与运算向左移继续执行以上。class Solution: def Add(self, num1, num2): while num2!=0: temp=num1^num2 ...原创 2019-02-25 17:22:32 · 290 阅读 · 0 评论 -
LeetCode 2: Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...原创 2019-02-25 16:12:24 · 103 阅读 · 0 评论 -
LeetCode 43: Multiply Strings (大数相乘)
Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.Example 1:Input: num1 = "2", num2 = "3"Output: "6"Example 2..原创 2019-02-25 14:18:55 · 303 阅读 · 0 评论 -
LeetCode 229: Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.Note: The algorithm should run in linear time and in O(1) space.Example 1:Input: [3,2,3]Output: [3]Example...原创 2019-02-28 23:23:15 · 120 阅读 · 0 评论 -
LeetCode 169: Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element alway...原创 2019-02-28 23:10:12 · 124 阅读 · 0 评论 -
LeetCode 153: Find Minimum 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]).Find the minimum element.You may assume no dupli...原创 2019-02-14 00:47:04 · 105 阅读 · 0 评论 -
LeetCode 81: Search in Rotated Sorted Array II
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]).You are given a target value to search. If found in...原创 2019-02-14 00:01:34 · 90 阅读 · 0 评论 -
LeetCode 94: Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes’ values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,3,2]Iterationclass Solution: def inorderTraversal...原创 2019-02-20 13:20:27 · 141 阅读 · 0 评论 -
LeetCode 69: Sqrt(x)
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 only t...原创 2019-03-06 22:23:47 · 190 阅读 · 0 评论 -
LeetCode 198: House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house...原创 2019-03-10 13:23:38 · 110 阅读 · 0 评论 -
LeetCode 213: House Robber II
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is ...原创 2019-03-10 13:25:31 · 69 阅读 · 0 评论 -
LeetCode 290: Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.Example ...原创 2019-03-15 17:17:22 · 95 阅读 · 0 评论 -
修桌子
Arthur最近搬到了新的别墅,别墅特别大,原先的桌子显得比较小,所以他决定换一张新的桌子。他买了一张特别大的桌子,桌子是由很多条桌腿进行支撑的,可是回到家之后他发现桌子不稳,原来是桌子腿长度不太相同。他想要自己把桌子修理好,所以他决定移除掉一些桌腿来让桌子变得平稳。桌子腿总共有n条腿,第i条腿长度为li,Arthur移除第i桌腿要花费代价为di。假设k条腿桌子平稳的条件:超过一半桌腿能够达...原创 2019-03-25 13:25:23 · 313 阅读 · 0 评论 -
有序数组的交集和并集
define two indexs starting from 0 for the arrays. Compare values the two indexs referring to, and move the indexs under each condition.The union of two sorted arraysdef union(list1, list2): l1...原创 2019-04-26 16:58:13 · 489 阅读 · 0 评论 -
字符串排列相关
All possible permutations of a stringdef permutation(prefix, s): if len(s) == 0: print(prefix) else: visit = set() for i in range(len(s)): if s[i] in vis...原创 2019-04-26 17:46:48 · 111 阅读 · 0 评论 -
算法之编程语言
文章目录引用、指针列表、元组is和==引用、指针列表、元组区别:元组不可变,列表可变,元组比列表更安全列表不可作为字典的键,元组可以元组占用内存更小,比列表操作跟快is和==python对象三要素:id、type、valueis比较的是id,即是否为同一对象,位于同一地址,==比较的是值,对于...原创 2019-02-16 00:47:56 · 1530 阅读 · 0 评论 -
LeetCode 33: Search in Rotated Sorted Array
This problem is little difference to LeetCode 81. Search in Rotated Sorted Array II. In this problem, it assumes that no duplicate exists in the array.Binary search is used to solve it. Iteration and...原创 2019-02-13 23:29:58 · 108 阅读 · 0 评论 -
LeetCode 108:Convert Sorted Array to Binary Search Tree
The Problem can be seen in Convert Sorted Array to Binary Search Tree,the analysis is shown in the following.A given array named as nums (like [-10,-3,0,5,9]) is sorted in ascending order.constructi...原创 2019-02-13 19:45:00 · 126 阅读 · 0 评论 -
LeetCode 704: Binary Search
Solving this by using iteration and recursion methodRecursionclass Solution: def search(self, nums: 'List[int]', target: 'int') -> 'int': def recursion(nums, l, r): if l&...原创 2019-02-13 23:07:47 · 74 阅读 · 0 评论 -
LeetCode 718: Maximum Length of Repeated Subarray
Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.Example 1:Input:A: [1,2,3,2,1]B: [3,2,1,4,7]Output: 3Explanation: The repeated subarray wi...原创 2019-02-16 23:20:47 · 89 阅读 · 0 评论 -
最大差值
有一个长为n的数组A,求满足0≤a≤b<n的A[b]-A[a]的最大值。给定数组A及它的大小n,请返回最大差值。测试样例:[10,5],2返回:0Greedy algorithm is used in this problem. The max difference is gotten in each step. max[i] = array[i] - minimum value...原创 2019-02-16 22:46:23 · 436 阅读 · 0 评论 -
LeetCode 442: Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without extra sp...原创 2019-02-16 20:47:24 · 118 阅读 · 0 评论 -
LeetCode 448: Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.Could ...原创 2019-02-16 20:41:06 · 101 阅读 · 0 评论 -
LeetCode 268: Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.Example 1:Input: [3,0,1]Output: 2Example 2:Input: [9,6,4,2,3,5,7,0,1]Output: 8...原创 2019-02-16 00:49:15 · 71 阅读 · 0 评论 -
LeetCode 572: Subtree of Another Tree
Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node...原创 2019-02-15 21:41:00 · 117 阅读 · 0 评论 -
Leetcode 1: Two Sum
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 the same e...原创 2019-02-15 15:23:52 · 131 阅读 · 0 评论 -
LeetCode 325: Maximum Size Subarray Sum Equals k
Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn’t one, return 0 instead.Hashmap is also used in this problem. Iterate the array and calcul...原创 2019-02-15 14:45:49 · 129 阅读 · 0 评论 -
LeetCode 525: Contiguous Array
Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.Using hashmap to solve it. Map<sum, index>, the hashmap only stores the sum of first (index +...原创 2019-02-15 14:18:46 · 133 阅读 · 0 评论 -
LeetCode 53: Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanation:...原创 2019-02-16 23:34:20 · 97 阅读 · 0 评论 -
LeetCode 121: Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), ...原创 2019-02-16 23:37:21 · 113 阅读 · 0 评论 -
Print linked list in reverse order
Recursionclass Solution: # 返回从尾部到头部的列表值序列,例如[1,2,3] def printListFromTailToHead(self, listNode): # write code here if listNode: return self.printListFromTailToHe...原创 2019-02-19 00:18:51 · 192 阅读 · 0 评论 -
Reconstruct binary tree
输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。Recursion is used to solve this problemclass Solution: # 返回构造的TreeNode根节点 ...原创 2019-02-19 00:09:11 · 478 阅读 · 0 评论 -
之字形打印二叉树
请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推。类似于层次遍历,只是需要判断奇偶层,如果为偶数层则需要反序输出Common methodclass Solution: def Print(self, pRoot): # write code here i...原创 2019-02-24 00:01:08 · 461 阅读 · 0 评论 -
LeetCode 191: Number of 1 Bits
n & (n-1) can remove the last zero 1 in binary format.class Solution(object): def hammingWeight(self, n): """ :type n: int :rtype: int """ res = 0 ...原创 2019-02-28 00:12:51 · 132 阅读 · 0 评论