- 博客(16)
- 收藏
- 关注
原创 scipy
1.Generate matrix A belongs to Rm*n with m > n. Also generate some vector b belongs to Rm.Now x = arg min ||Ax -b||2Print the norm of the residualm = 20n = 10A = np.random.rand(m,n)b = np.random...
2018-06-28 17:44:49
176
原创 matplotlib
Exercise 11.1: Plotting a functionx = np.linspace(-2, 2, 1000)y = np.power((np.sin(x - 2)), 2) * np.exp(-x * x)plt.plot(x, y)plt.show()程序运行结果Exercise 11.2: DataX = np.random.randint(10, 20, (20, 10...
2018-06-28 16:41:05
216
原创 numPy
import numpy as npimport scipy.linalg as sl;# 9.1print("matrix operations\n");def addMat(A): return A+Adef multAAT(A): return A*A.Tdef multATA(A): return A.T*Adef multAB(A,B): ...
2018-06-19 18:22:16
279
原创 letCode Median of Two Sorted Arrays (#4)
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [1, 3]nums2 ...
2018-06-19 15:35:46
149
原创 letCode Merge K Sorted Lists (#23)
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->2->3->4->4->5...
2018-06-19 15:34:20
134
原创 letCode Sort List (#148)
Sort a linked list in O(n log n) time using constant space complexity.解题思路:用归并排序的方法,因为表为链表,用快慢指针方法找到他的一半的位置,递归操作直到链表有序。代码如下:class ListNode: def __init__(self, x): self.val = x self...
2018-06-19 15:33:06
124
原创 leetCode#134 gas station
There are N gas stations along a circular route, where the amount of gas at station i isgas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel fromstation i to its nex...
2018-06-19 15:31:08
130
原创 python 文件和异常处理
#10-1 python学习笔记with open("learnpy.txt") as file_pro: contents = file_pro.read() print(contents)with open("learnpy.txt") as file_pro: for line in file_pro: print(line)with open("...
2018-04-23 09:29:24
758
原创 python 类
#9-1 餐馆 :创建一个名为 Restaurant 的类,其方法 __init__() 设置两个属性: restaurant_name 和 cuisine_type 。创建一个名#为 describe_restaurant() 的方法和一个名为 open_restaurant() 的方法,其中前者打印前述两项信息,而后者打印一条消息,指出餐馆正在营业。class Restaurant(): ...
2018-04-16 09:58:33
266
原创 python 方法
#8-2 喜欢的图书 :编写一个名为 favorite_book() 的函数,其中包含一个名为 title 的形参。这个函数打印一条消息,如 One of my favorite books is#Alice in Wonderland 。调用这个函数,并将一本图书的名称作为实参传递给它。def showBook(title): """显示喜欢的书籍""" print("my favorit...
2018-04-01 12:57:18
1665
原创 python input and while循环
#7-2 餐馆订位 :编写一个程序,询问用户有多少人用餐。如果超过 8 人,就打印一条消息,指出没有空桌;否则指出有空桌。dinnerNums = input("how many people will go to dinner?")if int(dinnerNums)>8: print("sorry, there is no enough disk")else: print('o...
2018-04-01 11:30:30
475
原创 python 字典
#6-1 人 :使用一个字典来存储一个熟人的信息,包括名、姓、年龄和居住的城市。该字典应包含键 first_name 、 last_name 、 age 和 city 。#将存储在该字典中的每项信息都打印出来。user_0 = {'first_name': 'han','last_name': "zheng" ,'age': 21 ,'city': 'gz'}print(user_0)pri...
2018-04-01 11:05:04
375
原创 python 条件语句
#5-2 更多的条件测试 :你并非只能创建 10 个测试。如果你想尝试做更多的比较,可再编写一些测试,并将它们加入到 conditional_tests.py 中。对于下面列出的各种测#试,至少编写一个结果为 True 和 False 的测试。#检查两个字符串相等和不等。#使用函数 lower() 的测试。#检查两个数字相等、不等、大于、小于、大于等于和小于等于。#使用关键字 and 和 or ...
2018-03-25 18:23:25
1806
原创 python 列表以及其操作
#3-1 姓名: 将一些朋友的姓名存储在一个列表中,并将其命名为 names 。依次访问该列表中的每个元素,从而将每个朋友的姓名都打印出来。#3-2 问候语: 继续使用练习 3-1 中的列表,但不打印每个朋友的姓名,而为每人打印一条消息。每条消息都包含相同的问候语,但抬头为相应朋友的姓名。names = ['silly','b','fff']print(names)for name in ...
2018-03-18 19:00:02
472
原创 python 第一周练习
#2-1 简单消息: 将一条消息存储到变量中,再将其打印出来。message = 'hello'print(message)#2-2 多条简单消息: 将一条消息存储到变量中,将其打印出来;再将变量的值修改为一条新消息,并将其打印出来。message = 'world'print(message)#2-3 个性化消息: 将用户的姓名存到一个变量中,并向该用户显示一条消息。显示的消息应非常简...
2018-03-11 21:24:16
253
原创 python 初体验,以及关于python项目的一些设想
这学期选了高级编程技术这门课程,其中所用到的编程语言就是python,所以应老师建议开设一个博客来记录python学习中的所学所思所感。 首先要做的事就是去访问官方文档库。此时也了解了python的一些特点。 1. 简单Python是一种代表简单思想的语言。 2. 易学Python有极其简单的语法。 3. 免费、开源Python是FLOSS(自由/开放源码软件)之一...
2018-03-11 19:15:25
314
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人