python学习
仗剑逐风
这个作者很懒,什么都没留下…
展开
-
sys.path 与 os.getcwd区分:代码运行中的路径问题
python 代码运行路径问题在下载使用别人的代码进行运行时,有时会遇到路径问题。将自己目前遇到的进行分类和总结。主要分为两类: import相关 open文件相关 问题的来源是:IDE和cmd的默认工作路径的差异,或模块搜索路径不同。(即可能是自己和对方使用的IDE的不同默认工作路径导致的。)当前工作目录文件读写等相关操作使用的基本路径。通过函数os.getcwd()获得通过函数os.chcwd()改变os.path功能:作为对路径进...原创 2021-06-13 17:31:16 · 453 阅读 · 2 评论 -
LeetCode 11. 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...原创 2018-04-24 14:34:10 · 76 阅读 · 0 评论 -
LeetCode #46Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.所能组成的用来积水的块,每一块需要两个板作为边界。当计算两个板之间的积水'面积'时,需要去除山的面积...原创 2018-04-28 08:51:14 · 99 阅读 · 0 评论 -
Exercise:学习使用Numpy
本文中涉及了矩阵的加、减、乘、转置等操作。主要是使用矩阵类的内置属性和方法以及numpy提供的方法来进行相关的操作:有需要的读者可以根据个人需要对照下方题目表涉及的方法进行查阅。前置生成相关矩阵import numpy as npfrom scipy.linalg import toeplitzn = 5m = 5A = np.random.randn(n,m)print( A )...原创 2018-05-19 18:11:20 · 159 阅读 · 0 评论 -
Exercise:Matplotlib入门
目的: 练习使用Matplotlib进行函数图像的绘制等数据处理任务。题目: 一:实现函数图像的绘制 import numpy as npimport matplotlib.pyplot as plt#import seaborn as snsx = np.linspace (0,2,1000) #interval#make it the functiony = np....原创 2018-05-26 15:48:05 · 209 阅读 · 0 评论 -
Exercise:Pandas and Statsmodels
Part 1For each of the four datasets...Compute the mean and variance of both x and yCompute the correlation coefficient between x and yCompute the linear regression line: y=β0+β1x+ϵy=β0+β1x+ϵ (hint: us...原创 2018-06-12 16:48:52 · 170 阅读 · 0 评论 -
Leetcode#34 Search for a Range
题目描述: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(lo...原创 2018-06-12 18:19:19 · 139 阅读 · 4 评论 -
Exercise: scipy
练习题目与相应代码如下:分析:使用最小二乘法:求出各个列向量线性组合后与b距离最小的线性组合#10.1import numpy as npimport scipy.optimize as opt#m > nm = 20 n = 10A = np.random.normal( loc = 10, scale = 3 , size = (m,n) ) #normalb = np...原创 2018-06-06 14:26:31 · 361 阅读 · 0 评论 -
Exercise: scikit-learn
Exercise:step1: sklearn自带生成数据集的函数from sklearn.datasets import make_classificationdatas = make_classification( n_samples = 1000, n_features=10 , )step2: cross-validation:交叉验证,将数据集分为两部分:训练集和评估集fr...原创 2018-06-19 09:38:34 · 203 阅读 · 0 评论 -
LeetCode #55jump game
'''#55jump gamesGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Det...原创 2018-04-30 10:05:03 · 120 阅读 · 0 评论 -
python编程从入门到实践第十章习题答案
#10-1 文件读取并输出到屏幕with open("learning_python.txt" , "r" ) as file: contents = file.read() print( contents ) print( "********************") for ele in contents: prin...原创 2018-04-05 10:02:33 · 460 阅读 · 0 评论 -
python编程从入门到实践第九章习题答案
#9-1class Restaurant() : def __init__( self , _name , _type ): self.restaurant_name = _name self.cuisine_type = _type def describe_restaurant( self ): print("The name...原创 2018-04-05 09:00:41 · 349 阅读 · 0 评论 -
python编程从入门到实践第四章习题答案
4.1pizza = ['a' , 'b' , 'c' ]for ele in pizza : print( ele + " . I like pepperoni pizza." )print( "They are delicious, I like them" )4.2animals = ['dog' , 'cat' , 'bird' ]for ele in animals : ...原创 2018-03-15 08:58:48 · 598 阅读 · 0 评论 -
python编程从入门到实践第三章习题答案
3.1-3.2names = ['zhichao' , 'yujie' , 'yifei']for name in names: print( name.title() + " , good night.")3.3transportation = ['car' , 'walk', 'bicycle' , 'motorcycle']for elem in transportatio...原创 2018-03-12 23:27:03 · 2135 阅读 · 0 评论 -
python编程从入门到实践第七章习题答案
#7-1 输入输出message = input( "What car do you want?")print( "Let me see if i can find you a ", message)#7-2 判断是否有空桌number = input( "How many people are having the dinner?")number = int( number)if numb...原创 2018-03-29 21:06:25 · 807 阅读 · 0 评论 -
python编程从入门到实践第五章习题答案
#5.2cars = [ 'bwm' , 'audi' , 'subaru' ]a_str = 'BWM'print( a_str == cars[0] )print( a_str.lower() == cars[0] )print( a_str.lower() in cars )print( a_str.lower() not in cars )#5.3-5.5#5.3alien_...原创 2018-03-20 21:42:51 · 294 阅读 · 0 评论 -
python编程从入门到实践第六章习题答案
#6.1 人people = { "first_name" : 'zetrue' , "last_name": 'Lee' , "age": 20 , "city" : "汕尾" }print( people)for key in people.keys() : print( key , " : " , people[key] )#6.2 喜欢的数字favorite_val原创 2018-03-21 21:57:46 · 1019 阅读 · 0 评论 -
python编程从入门到实践第八章习题答案
#8-2 喜欢的图书def favorite_book( book ) : print( "One of my favorite books is " , book )name = input( )favorite_book( name )#8-3 T恤def make_shirt( size , text ): print( "The size is :",size...原创 2018-04-01 19:43:17 · 637 阅读 · 0 评论 -
python编程从入门到实践第二章习题答案
请对照相关书籍进行阅读2.1-2.2message = "Hello Python!"print( message )message = "Hello Zhichao"print ( message ) 2.3message = "ada"print( "Hello " + message + ",would you like to learn some Python today?" ...原创 2018-03-07 23:24:42 · 734 阅读 · 0 评论