- 博客(18)
- 收藏
- 关注
原创 sklearn
1.GaussianNB# -*- coding: utf-8 -*-"""Created on Wed Jun 20 19:23:06 2018@author: 12046"""from sklearn import datasets,cross_validation from sklearn.naive_bayes import GaussianNB from sklea...
2018-06-20 20:09:25
1115
原创 scipy 习题
10.1# -*- coding: utf-8 -*-"""Created on Mon Jun 4 20:38:48 2018@author: 12046"""import numpyimport scipy.linalgm=5n=3A=numpy.random.random(size=(m,n))b=numpy.random.random(size=(m))x...
2018-06-04 21:16:41
200
原创 matplotlib 习题
11.1# -*- coding: utf-8 -*-"""Created on Tue May 29 19:34:16 2018@author: 12046"""import numpy as npimport scipyimport matplotlib.pyplot as pltdef f(x): return (np.sin(x-2)**2)*(np.e**(-...
2018-05-30 12:32:01
287
原创 numpy problem
9.1# -*- coding: utf-8 -*-"""Created on Mon May 21 20:55:33 2018@author: 12046"""import numpy as npfrom scipy.linalg import toeplitzdef f(A,B,mylambda): size=B.shape[1] print(A.dot(B-...
2018-05-21 22:21:43
192
原创 Leetcode 84
题意给定n个非负整数,表示每个小节的宽度为1的直方图的小节高度,找到直方图中最大矩形的面积。代码class Solution: def largestRectangleArea(self, heights): """ :type heights: List[int] :rtype: int """ sta=[(...
2018-05-01 23:11:47
173
原创 Leetcode 45
题意给定一个非负整数数组,您最初位于数组的第一个位置。数组中的每个元素表示您在该位置的最大跳跃长度。你的目标是用最小跳跃次数跳到最后一个位置。样例输入[2,3,1,1,4]样例输出2代码class Solution: def jump(self, nums): """ :type nums: List[int] :rtype: int ...
2018-05-01 21:39:51
276
原创 Leetcode 298
题意给定一个n*m的网格,每个单元都有一个细胞,每个细胞具有初始状态活(1)或死(0)。每个细胞使用以下四条规则与其八个邻居(水平,垂直,对角线)交互作用: 任何少于两个活着的邻居的活细胞都会死亡。 任何有两三个活着的邻居的活细胞都会继续存活。 任何有三个以上活着的邻居的活细胞都会死亡。 具有三个活的邻居的死细胞都会变成一个活细胞。 任根据当前状态写一个函数来计算板的...
2018-05-01 21:04:46
451
原创 第十一章python作业
11-1 城市和国家 :编写一个函数,它接受两个形参:一个城市名和一个国家名。这个函数返回一个格式为City, Country 的字符串,如Santiago, Chile 。将这个函数存储在一个名为city_functions.py的模块中。创建一个名为test_cities.py的程序,对刚编写的函数进行测试(别忘了,你需要导入模块unittest 以及要测试的函数)。编写一个名为test_ci...
2018-04-15 19:54:02
311
原创 第十章python作业
10-3 访客 :编写一个程序,提示用户输入其名字;用户作出响应后,将其名字写入到文件guest.txt中。name=input("Please input your name:")with open("guest.txt","w") as file_object: file_object.write(name)10-4 访客名单 :编写一个while 循环,提示用户输入其名字。用户输入其名...
2018-04-08 22:40:41
324
原创 第九章python作业
9-1 餐馆 :创建一个名为Restaurant 的类,其方法__init__() 设置两个属性:restaurant_name 和cuisine_type 。创建一个名为describe_restaurant() 的方法和一个名为open_restaurant() 的方法,其中前者打印前述两项信息,而后者打印一条消息,指出餐馆正在营业。class Restaurant(): def __ini...
2018-04-08 21:57:16
445
原创 第八章python作业
8-3 T恤 :编写一个名为make_shirt() 的函数,它接受一个尺码以及要印到T恤上的字样。这个函数应打印一个句子,概要地说明T恤的尺码和字样。def make_shirt(size,word): print("The size of this T-shirt:"+size) print("The word of this T-shirt:"+word+'\n')make...
2018-03-31 15:13:32
1737
原创 第7章python作业
7-2 餐馆订位 :编写一个程序,询问用户有多少人用餐。如果超过8人,就打印一条消息,指出没有空桌;否则指出有空桌。number=input("How many people? Please:")num=int(number)if num>8: print("Sorry, There is no empty table.")else: print("We have em...
2018-03-31 14:29:01
598
原创 第六章python作业
6-1 人 :使用一个字典来存储一个熟人的信息,包括名、姓、年龄和居住的城市。该字典应包含键first_name 、last_name 、age 和city 。将存储在该字典中的每项信息都打印出来。friend={ "first_name":"LeBron", "last_name":"James", "age":"34", "city":"Cleve
2018-03-23 21:00:27
754
原创 第五章python作业
5-3 外星人颜色#1 :假设在游戏中刚射杀了一个外星人,请创建一个名为alien_color 的变量,并将其设置为'green' 、'yellow' 或'red' 。编写一条if 语句,检查外星人是否是绿色的;如果是,就打印一条消息,指出玩家获得了5个点。编写这个程序的两个版本,在一个版本中上述测试通过了,而在另一个版本中未通过(未通过测试时没有输出)。alien_color='green'i...
2018-03-23 20:28:17
439
原创 第四章python作业
4-2 动物 :想出至少三种有共同特征的动物,将这些动物的名称存储在一个列表中,再使用for 循环将每种动物的名称都打印出来。修改这个程序,使其针对每种动物都打印一个句子,如“A dog would make a great pet”。在程序末尾添加一行代码,指出这些动物的共同之处,如打印诸如“Any of these animals would make a great pet!”这样的句子。&...
2018-03-16 21:23:42
732
原创 第三章python作业
3-1 姓名: 将一些朋友的姓名存储在一个列表中,并将其命名为names 。依次访问该列表中的每个元素,从而将每个朋友的姓名都打印出来。>>> names=['James','Kobe','Alice','Bob']>>> print(names)['James', 'Kobe', 'Alice', 'Bob']>>> print(nam...
2018-03-16 21:02:14
616
原创 初识python
Python 主页 Python主页(https://www.python.org/)上有许多关于Python的资源,主页上有Python的下载,Python的帮助文档,社区,成功案例,以及新闻。作为初学者,我们应多浏览Python主页,获取更多Python的知识。 Python主页上的getting started 板块主要为初学者提供帮助。这个板块里面给出了许多官方的帮组文...
2018-03-11 13:54:09
544
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人