- 博客(19)
- 收藏
- 关注
原创 第十五周_sklearn题目
题目描述:代码实现:# coding=utf-8from sklearn import datasetsfrom sklearn import cross_validationfrom sklearn.naive_bayes import GaussianNBfrom sklearn.svm import SVCfrom sklearn.ensemble import RandomFor...
2018-06-19 23:36:27 160
原创 第十四周_Jupyter题目
Anscombe's quartetAnscombe's quartet comprises of four datasets, and is rather famous. Why? You'll find out in this exercise.%matplotlib inlineimport randomimport numpy as npimport scipy as spimpo...
2018-06-10 11:41:15 286
原创 第十三周_Scipy题目
Exercise 10.1: Least squares 题目描述:Generate matrix A ∈ R m×n with m > n. Also generate some vector b ∈ Rm. Now find x = argminx||Ax−b||2. Print the norm of the residual.代码实现:from scipy.optimize impor...
2018-05-31 13:34:56 324
原创 第十二周_Matplotlib题目
Exercise 11.1: 题目描述: Plotting a function Plot the functionf(x) = sin2(x−2)e−x2 over the interval [0,2]. Add proper axis labels, a title, etc.代码:运行结果:
2018-05-27 09:12:31 261
原创 第十一周_Numpy题目
Exercise 9.1: 题目描述:Matrix operations Calculate A + A, AA>,A>A and AB. Write a function that computes A(B−λI) for any λ.代码:import numpy as np from scipy.linalg import toeplitz A = np.mat(n...
2018-05-20 17:42:35 285
原创 第十周_Leetcode
题目:344. Reverse String题目描述:Write a function that takes a string as input and returns the string reversed.测试样例:Given s = "hello", return "olleh".思路分析:string是不可变数组类型,要想改变字符串顺序需要采用s1 = s1[:i]+s[n-1-i]+s1...
2018-05-20 09:04:55 125
原创 第九周_Leetcode
题目一:485. Max Consecutive Ones题目描述:Given a binary array, find the maximum number of consecutive 1s in this array.Note:The input array will only contain 0 and 1.The length of input array is a positive i...
2018-05-02 20:39:11 92
原创 第八周_LeetCode
题目一:88. Merge Sorted Array题目描述:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n respec...
2018-04-26 01:09:53 93
原创 第六周作业_Chapter 11课后练习
11-1 城市和国家代码:1、city_functions.py:def show_city(city,country): message = city + ", " + country return message2、test.py:import unittestfrom city_functions import show_cityclass CityTestCase(unittest.Tes...
2018-04-03 20:32:52 255
原创 第五周作业_Chapter 10课后练习
10-1 Python学习笔记代码:with open('learning_python.txt') as fo: content = fo.read() print(content) print("------------------------------------------------")with open('learning_python.txt') as fo: for line i...
2018-04-02 20:14:17 212
原创 第五周作业_Chapter 9课后练习
9-1、9-2 餐馆代码:class Restaurant(): def __init__(self,restaurant_name,cuisine_type): self.restaurant_name = restaurant_name self.cuisine_type = cuisine_type def describe_restaurant(self): message = s...
2018-04-02 09:58:19 151
原创 第四周作业_Chapter 8课后练习
8-2 喜欢的图书代码:def favorite_book(bookname): print("One of my favorite books is " + bookname + ".")favorite_book('Harry Potter')运行结果:8-4大号T恤代码:def make_shirt(size = 'L', message = 'I love python'): print(...
2018-03-29 13:09:16 187
原创 第四周作业_Chapter 7课后练习
7-2 餐馆订位代码:num = input("How many people are coming for dinner?")num = int(num)if num<=8 : print("There are empty tables.")else: print("None of table is available.")运行结果:7-5 电影票代码:while True: age = ...
2018-03-29 10:48:08 161
原创 第三周作业_Chapter 6课后练习
6-1 人代码:person = {'firstname':'Chunk','lastname':'Bass','age':18,'city':'Manhattan'}print(person['firstname'])print(person['lastname'])print(person['age'])print(person['city'])运行结果:6-5 河流代码:rivers = {...
2018-03-25 10:45:14 180
原创 第三周作业_Chapter 5课后练习
5-2 更多的条件测试代码:# test1str1 = "abc"print(str1 == "abc")# test2str2 = "ABC"print(str2.lower() == "abc")# test3print(1.5 == 1.5)print(1.5 != 1.5)print(1.5 >= 1.5)print(3 > 2)print(3 < 2)print(1 &
2018-03-25 09:53:56 228
原创 第二周作业_Chapter 4课后练习
4-2 动物代码:animals = ['cat','dog','fish']for animal in animals: print(animal)for animal in animals: print("A " + animal + " would make a great pet.")print("Any of these animals would make a great pet!")...
2018-03-14 23:53:47 198
原创 第二周作业_Chapter 3 课后练习
3-2 问候语代码:names = ['Mary','Tony','Nate']message = names[0] + ", nice to meet you."print(message)message = names[1] + ", nice to meet you."print(message)message = names[2] + ", nice to meet you."print(...
2018-03-14 23:08:03 210
原创 第一周作业_Chapter 2 课后练习
2-1 简单消息代码:favorite_fruit = "apples"print(favorite_fruit)运行结果:2-2 多条简单消息代码:favorite_fruit = "apples"print(favorite_fruit)favorite_fruit = "pears"print(favorite_fruit)运行结果:2-3 个性化信息代码:usename = "Adam"s...
2018-03-11 11:09:49 172
原创 第一周作业_hello python world
第一次接触python,发现作为高级编程语言的它和之前学的C++和C有很多不同。最大的特点是语法上的不同。之前学过的两种语言,C++在C的基础上产生的,所以他们之间的语法有很大的相似性。而python却有很大的区别。C++的语法很严谨,也有更多的细节上的要求,而python的语法却相对灵活随意一些。比如可以对两个变量同时赋值,用逗号将变量隔开。如 a,b=0,1 即可实现 a=0,b=1 的操作。...
2018-03-05 23:16:25 244
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人