摘要:
1 r2 = r[:3,:3] 2 r2 array([[ 0, 1, 2], [ 6, 7, 8], [12, 13, 14]]) 1 r2[:] = 0 2 r2 array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])此时r= array([[ 0, 0, 0, 3, 阅读全文
摘要:
1 s = np.arange(13)**2 2 s array([ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144]) 1 s[0], s[4], s[-1] (0, 16, 144) 1 s[1:5] array([ 1, 4, 9, 16]) 阅读全文
摘要:
1 a = np.array([-4, -2, 1, 3, 5]) 2 a.sum() 3 1 a.max() 5 1 a.min() -4 1 a.mean() 0.60 1 a.std() 3.26 1 a.argmax() 4 1 a.argmin() 0 阅读全文
摘要:
1 print(x + y) # elementwise addition [1 2 3] + [4 5 6] = [5 7 9] 2 print(x - y) # elementwise subtraction [1 2 3] - [4 5 6] = [-3 -3 -3] [5 7 9] [-3 阅读全文
摘要:
1 import numpy as np %通过链表创建数组1 mylist = [1, 2, 3] 2 x = np.array(mylist) 3 x array([1, 2, 3]) %直接创建数组1 y = np.array([4, 5, 6]) 2 y array([4, 5, 6]) %创建多维数组1 m = np.array([[7, 8, 9], [10, 11,... 阅读全文
摘要:
%下面是lambda的示例,它包含三个参数并添加前两个参数。1 my_function = lambda a, b, c : a + b 2 my_function(1, 2, 3) 3 1 my_list = [] 2 for number in range(0, 1000): 3 if numb 阅读全文
摘要:
1 class Person: 2 department = 'School of Information' #a class variable 3 4 def set_name(self, new_name): #a method 5 self.name = new_name 6 def set_ 阅读全文
摘要:
1 import datetime as dt 2 import time as tm %时间从纪元开始以秒为单位返回当前时间。(1970年1月1日)1 tm.time() 1520242063.03 1 dtnow = dt.datetime.fromtimestamp(tm.time()) 2 阅读全文
摘要:
Let's import our datafile mpg.csv, which contains fuel economy data for 234 cars. mpg : miles per gallon class : car classification cty : city mpg cyl 阅读全文
摘要:
1 print('Chris' + 2) TypeError Traceback (most recent call last) <ipython-input-37-82ccfdd3d5d3> in <module>() > 1 print('Chris' + 2) TypeError: must 阅读全文
摘要:
%解压序列到不同的变量中1 x = ('Christopher', 'Brooks', 'brooksch@umich.edu') 2 fname, lname, email = x 1 fname 'Christopher' 1 lname 'Brooks' %确保变量的数量和解压的值相同1 x = ('Christopher', 'Brooks', 'brooksch@umi... 阅读全文
摘要:
%字典用keys来连接values1 x = {'Christopher Brooks': 'brooksch@umich.edu', 'Bill Gates': 'billg@microsoft.com'} 2 x['Christopher Brooks'] # Retrieve a value 阅读全文
摘要:
list 阅读全文
摘要:
tuple 阅读全文
摘要:
NoneType int float function 阅读全文
摘要:
输出:3 输出:3 6 输出: 输出:3 阅读全文