摘要:
程序文件ex2_30.py import numpy as np a = np.array([[0, 3, 4], [1, 6, 4]]) b = a.sum() #使用方法,求矩阵所有元素的和 c1 = sum(a) #使用内置函数,求矩阵逐列元素的和 c2 = np.sum(a, axis=0) 阅读全文
posted @ 2024-10-14 11:43
qi11
阅读(21)
评论(0)
推荐(0)
摘要:
程序文件ex2_28.py import numpy as np a = np.arange(16).reshape(4,4) #生成4行4列的数组 b = np.floor(5np.random.random((2, 4))) c = np.ceil(6np.random.random((4, 2 阅读全文
posted @ 2024-10-14 11:31
qi11
阅读(14)
评论(0)
推荐(0)
摘要:
程序文件ex2_26.py import numpy as np a = np.ones(4, dtype=int) #输出[1, 1, 1, 1] b = np.ones((4,), dtype=int) #同a c= np.ones((4,1)) #输出4行1列的数组 d = np.zeros( 阅读全文
posted @ 2024-10-14 11:31
qi11
阅读(9)
评论(0)
推荐(0)
摘要:
程序文件ex2_24.py s1=[str(x)+str(y) for x,y in zip(['v']*4,range(1,5))] s2=list(zip('abcd',range(4))) print(s1); print(s2) 阅读全文
posted @ 2024-10-14 11:30
qi11
阅读(18)
评论(0)
推荐(0)
摘要:
程序文件ex2_22.py a = filter(lambda x: x>10,[1,11,2,45,7,6,13]) b = filter(lambda x: x.isalnum(),['abc', 'xy12', '***']) isalnum()是测试是否为字母或数字的方法 print(lis 阅读全文
posted @ 2024-10-14 11:29
qi11
阅读(12)
评论(0)
推荐(0)
摘要:
程序文件ex2_20.py x1="abcde" x2=list(enumerate(x1)) for ind,ch in enumerate(x1): print(ch) 阅读全文
posted @ 2024-10-14 11:28
qi11
阅读(10)
评论(0)
推荐(0)
摘要:
程序文件ex2_18.py from ex2_12_2 import * print(factorial(6)) fib(300) 阅读全文
posted @ 2024-10-14 11:28
qi11
阅读(10)
评论(0)
推荐(0)
摘要:
程序文件ex2_16.py from random import sample from numpy.random import randint a=sample(range(10),5) #在[0,9]区间上选择不重复的5个整数 b=randint(0,10,5) #在[0,9]区间上生成5个随机 阅读全文
posted @ 2024-10-14 11:28
qi11
阅读(12)
评论(0)
推荐(0)
摘要:
程序文件ex2_14.py f=lambda x, y, z: xyz L=lambda x: [x2, x3, x**4] print(f(3,4,5)); print(L(2)) 阅读全文
posted @ 2024-10-14 11:26
qi11
阅读(19)
评论(0)
推荐(0)
摘要:
程序文件ex2_12_3.py from ex2_12_2 import factorial, fib print('%d!=%d'%(5,factorial(5))) fib(200) 阅读全文
posted @ 2024-10-14 11:25
qi11
阅读(11)
评论(0)
推荐(0)
摘要:
程序文件ex2_12_2.py def factorial(n): #定义阶乘函数 r = 1 while n > 1: r *= n n -= 1 return r def fib(n): #定义输出斐波那契数列函数 a, b = 1, 1 while a < n: print(a, end=' 阅读全文
posted @ 2024-10-14 11:25
qi11
阅读(13)
评论(0)
推荐(0)
摘要:
程序文件ex2_11_2.py import string, random, collections #依次加载三个模块 x=string.ascii_letters+string.digits y=''.join([random.choice(x) for i in range(1000)]) c 阅读全文
posted @ 2024-10-14 11:24
qi11
阅读(11)
评论(0)
推荐(0)
摘要:
程序文件ex2_11_1.py import string import random x=string.ascii_letters+string.digits y=''.join([random.choice(x) for i in range(1000)]) choice()用于从多个元素中随机 阅读全文
posted @ 2024-10-14 11:24
qi11
阅读(28)
评论(0)
推荐(0)
摘要:
程序文件ex2_10.py Dict={'age':18, 'score':[98,97], 'name':'Zhang', 'sex':'male'} for item in Dict: #遍历输出字典的“键” print(item) print(" " ) for item in Dict.it 阅读全文
posted @ 2024-10-14 11:23
qi11
阅读(21)
评论(0)
推荐(0)
摘要:
程序文件ex2_8.py dict1 ={'Alice': '123', 'Beth': '456', 'Cecil': 'abc'} print(dict1['Alice']) #输出123 dict1['new'] = 'Hello' #增加新的键值对 dict1['Alice'] = '123 阅读全文
posted @ 2024-10-14 10:17
qi11
阅读(49)
评论(0)
推荐(0)
摘要:
程序文件ex2_7.py student = {'Tom', 'Jim', 'Mary', 'Tom', 'Jack', 'Rose'} print(student) a = set('abcdabc') print(a) #每次输出是不一样的,如输出:{'d', 'b', 'a', 'c'} 阅读全文
posted @ 2024-10-14 10:16
qi11
阅读(17)
评论(0)
推荐(0)
摘要:
程序文件ex2_6.py T = ('abc', 12, 3.45, 'Python', 2.789) print(T) #输出完整元组 print(T[-1]) #输出元组的最后一个元素 print(T[1:3]) #输出元组的第二、三元素 阅读全文
posted @ 2024-10-14 10:16
qi11
阅读(16)
评论(0)
推荐(0)
摘要:
程序文件ex2_5_2.py from numpy.random import randint import numpy as np a=randint(10,20,16) #生成16个[10,20)上的随机整数 ma=max(a) ind1=[index for index,value in en 阅读全文
posted @ 2024-10-14 10:15
qi11
阅读(15)
评论(0)
推荐(0)
摘要:
程序文件ex2_5_1.py import os fn=[filename for filename in os.listdir('D:\Programs\Python\Python37') if filename.endswith(('.exe','.py'))] print(fn) 阅读全文
posted @ 2024-10-14 10:15
qi11
阅读(7)
评论(0)
推荐(0)
摘要:
程序文件ex2_4.py a=[[1,2,3],[4,5,6],[7,8,9]] d=[c for b in a for c in b] print(d) 阅读全文
posted @ 2024-10-14 09:53
qi11
阅读(40)
评论(0)
推荐(0)
摘要:
程序文件ex2_3.py L = ['abc', 12, 3.45, 'Python', 2.789] print(L) #输出完整列表 print(L[0]) #输出列表的第一个元素 L[0] = 'a' #修改列表的第一个元素 L[1:3] = ['b', 'Hello'] #修改列表的第二、三 阅读全文
posted @ 2024-10-14 09:53
qi11
阅读(14)
评论(0)
推荐(0)
摘要:
程序文件ex2_2.py import numpy as np a=[] with open('data2_2.txt') as f: for (i, s) in enumerate(f): a.append([s.count('a'), s.count('c'), s.count('g'),s.c 阅读全文
posted @ 2024-10-14 09:52
qi11
阅读(57)
评论(0)
推荐(0)
摘要:
-- coding: utf-8 -- """ Created on Sun Oct 13 11:32:13 2024 @author: 26606 """ str1="Hellow World!" print(str1) print(str1[0:-1]) print(str1[-1]) prin 阅读全文
posted @ 2024-10-14 09:51
qi11
阅读(5)
评论(0)
推荐(0)

浙公网安备 33010602011771号