摘要:
`import pylab as plt import numpy as np ax=plt.axes(projection='3d') X = np.arange(-6, 6, 0.25) Y = np.arange(-6, 6, 0.25) X, Y = np.meshgrid(X, Y) Z 阅读全文
posted @ 2024-10-28 12:22
VVV1
阅读(16)
评论(0)
推荐(0)
摘要:
`import pylab as plt import numpy as np x=np.linspace(-4,4,100); x,y=np.meshgrid(x,x) z=50*np.sin(x+y); ax=plt.axes(projection='3d') ax.plot_surface(x 阅读全文
posted @ 2024-10-28 12:21
VVV1
阅读(15)
评论(0)
推荐(0)
摘要:
`import pylab as plt import numpy as np ax=plt.axes(projection='3d') #设置三维图形模式 z=np.linspace(-50, 50, 1000) x=z2*np.sin(z); y=z2*np.cos(z) plt.plot(x, 阅读全文
posted @ 2024-10-28 12:20
VVV1
阅读(25)
评论(0)
推荐(0)
摘要:
`import pylab as plt import numpy as np plt.rc('text', usetex=True) #调用tex字库 y1=np.random.randint(2, 5, 6); y1=y1/sum(y1); plt.subplot(2, 2, 1); str=[ 阅读全文
posted @ 2024-10-28 12:20
VVV1
阅读(14)
评论(0)
推荐(0)
摘要:
`import pandas as pd import pylab as plt plt.rc('font',family='SimHei') #用来正常显示中文标签 plt.rc('font',size=16) #设置显示字体大小 a=pd.read_excel("data2_52.xlsx",h 阅读全文
posted @ 2024-10-28 12:19
VVV1
阅读(23)
评论(0)
推荐(0)
摘要:
`import pandas as pd import pylab as plt plt.rc('font',family='SimHei') #用来正常显示中文标签 plt.rc('font',size=16) #设置显示字体大小 a=pd.read_excel("data2_52.xlsx", 阅读全文
posted @ 2024-10-28 12:19
VVV1
阅读(18)
评论(0)
推荐(0)
摘要:
`import numpy as np import sympy as sp a = np.identity(4) #单位矩阵的另一种写法 b = np.rot90(a) c = sp.Matrix(b) print('特征值为:', c.eigenvals()) print('特征向量为:\n', 阅读全文
posted @ 2024-10-28 12:18
VVV1
阅读(25)
评论(0)
推荐(0)
摘要:
`import sympy as sp sp.var('x1,x2') s=sp.solve([x12+x22-1,x1-x2],[x1,x2]) print(s) print("学号:3005")` 阅读全文
posted @ 2024-10-28 12:17
VVV1
阅读(11)
评论(0)
推荐(0)
摘要:
`import sympy as sp a, b, c, x=sp.symbols('a,b,c,x') x0=sp.solve(ax**2+bx+c, x) print(x0) print("学号:3005")` 阅读全文
posted @ 2024-10-28 12:16
VVV1
阅读(23)
评论(0)
推荐(0)
摘要:
`from scipy.sparse.linalg import eigs import numpy as np a = np.array([[1, 2, 3], [2, 1, 3], [3, 3, 6]], dtype=float) #必须加float,否则出错 b, c = np.linalg. 阅读全文
posted @ 2024-10-28 12:16
VVV1
阅读(48)
评论(0)
推荐(0)
摘要:
`from scipy.optimize import least_squares import numpy as np a=np.loadtxt('data2_47.txt') x0=a[0]; y0=a[1]; d=a[2] fx=lambda x: np.sqrt((x0-x[0])2+(y0 阅读全文
posted @ 2024-10-28 12:15
VVV1
阅读(36)
评论(0)
推荐(0)
摘要:
`from scipy.integrate import quad def fun42(x, a, b): return ax**2+bx I1 = quad(fun42, 0, 1, args=(2, 1)) I2 = quad(fun42, 0, 1, args=(2, 10)) print(I 阅读全文
posted @ 2024-10-28 12:14
VVV1
阅读(14)
评论(0)
推荐(0)
摘要:
`from scipy.optimize import fsolve, root fx = lambda x: [x[0]2+x[1]2-1, x[0]-x[1]] s1 = fsolve(fx, [1, 1]) s2 = root(fx, [1, 1]) print(s1,'\n',' '); p 阅读全文
posted @ 2024-10-28 12:14
VVV1
阅读(14)
评论(0)
推荐(0)
摘要:
`from scipy.optimize import fsolve, root fx = lambda x: x980-5.01*x979+7.398x**978 -3.388x977-x3+5.01x**2-7.398x+3.388 x1 = fsolve(fx, 1.5, maxfev=400 阅读全文
posted @ 2024-10-28 12:13
VVV1
阅读(19)
评论(0)
推荐(0)
摘要:
`import numpy as np a=np.random.rand(6,8) #生成6×8的[0,1)上均匀分布的随机数矩阵 np.savetxt("data2_43_1.txt", a) #存成以制表符分隔的文本文件 np.savetxt("data2_43_2.csv", a, delim 阅读全文
posted @ 2024-10-28 12:12
VVV1
阅读(12)
评论(0)
推荐(0)
摘要:
`import pandas as pd import numpy as np a = pd.DataFrame(np.random.randint(1,6,(5,3)), index=['a', 'b', 'c', 'd', 'e'], columns=['one', 'two', 'three' 阅读全文
posted @ 2024-10-28 12:10
VVV1
阅读(12)
评论(0)
推荐(0)
摘要:
`import pandas as pd import numpy as np d=pd.DataFrame(np.random.randint(1,6,(10,4)), columns=list("ABCD")) d1=d[:4] #获取前4行数据 d2=d[4:] #获取第5行以后的数据 dd= 阅读全文
posted @ 2024-10-28 12:09
VVV1
阅读(21)
评论(0)
推荐(0)
摘要:
`with open('data2_2.txt') as fp: L1=[]; L2=[]; for line in fp: L1.append(len(line)) L2.append(len(line.strip())) #去掉换行符 data = [str(num)+'\t' for num 阅读全文
posted @ 2024-10-28 12:08
VVV1
阅读(11)
评论(0)
推荐(0)
摘要:
`import pandas as pd a=pd.read_csv("data2_38_2.csv", usecols=range(1,5)) b=pd.read_excel("data2_38_3.xlsx", "Sheet2", usecols=range(1,5)) print("学号:30 阅读全文
posted @ 2024-10-28 12:07
VVV1
阅读(12)
评论(0)
推荐(0)
摘要:
2.38.1 `import pandas as pd import numpy as np dates=pd.date_range(start='20191101', end='20191124', freq='D') a1=pd.DataFrame(np.random.randn(24,4), 阅读全文
posted @ 2024-10-28 12:06
VVV1
阅读(15)
评论(0)
推荐(0)
摘要:
`import pandas as pd import numpy as np dates=pd.date_range(start='20191101',end='20191124',freq='D') a1=pd.DataFrame(np.random.randn(24,4), index=dat 阅读全文
posted @ 2024-10-28 12:05
VVV1
阅读(10)
评论(0)
推荐(0)
摘要:
`import numpy as np a = np.eye(4) b = np.rot90(a) c, d = np.linalg.eig(b) print('特征值为:', c) print('特征向量为:\n', d) print("学号:3005")` 阅读全文
posted @ 2024-10-28 12:04
VVV1
阅读(21)
评论(0)
推荐(0)
摘要:
`import numpy as np a = np.array([[3, 1], [1, 2], [1, 1]]) b = np.array([9, 8, 6]) x = np.linalg.pinv(a) @ b print(np.round(x, 4)) print("学号:3005")` 阅读全文
posted @ 2024-10-28 12:03
VVV1
阅读(18)
评论(0)
推荐(0)
摘要:
`import numpy as np a = np.array([[3, 1], [1, 2]]) b = np.array([9, 8]) x1 = np.linalg.inv(a) @ b #第一种解法 上面语句中@表示矩阵乘法 x2 = np.linalg.solve(a, b) #第二种解 阅读全文
posted @ 2024-10-28 12:03
VVV1
阅读(14)
评论(0)
推荐(0)
摘要:
`import numpy as np a = np.array([[0, 3, 4], [1, 6, 4]]) b = np.linalg.norm(a, axis=1) #求行向量2范数 c = np.linalg.norm(a, axis=0) #求列向量2范数 d = np.linalg.n 阅读全文
posted @ 2024-10-28 12:02
VVV1
阅读(64)
评论(0)
推荐(0)
摘要:
`import numpy as np a = np.ones(4) b = np.arange(2, 10, 2) c = a @ b #a作为行向量,b作为列向量 d = np.arange(16).reshape(4,4) f = a @ d #a作为行向量 g = d @ a #a作为列向量 阅读全文
posted @ 2024-10-28 12:02
VVV1
阅读(17)
评论(0)
推荐(0)
摘要:
`import numpy as np a = np.array([[0, 3, 4], [1, 6, 4]]) b = np.array([[1, 2, 3], [2, 1, 4]]) c = a / b #两个矩阵对应元素相除 d = np.array([2, 3, 2]) e = a * d 阅读全文
posted @ 2024-10-28 12:01
VVV1
阅读(12)
评论(0)
推荐(0)
摘要:
`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-28 12:00
VVV1
阅读(31)
评论(0)
推荐(0)
摘要:
`import numpy as np a = np.arange(16).reshape(4,4) #生成4行4列的数组 b = np.vsplit(a, 2) #行分割 print('行分割:\n', b[0], '\n', b[1]) c = np.hsplit(a, 4) #列分割 prin 阅读全文
posted @ 2024-10-28 12:00
VVV1
阅读(16)
评论(0)
推荐(0)
摘要:
`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))) d = np.vs 阅读全文
posted @ 2024-10-28 11:59
VVV1
阅读(16)
评论(0)
推荐(0)
摘要:
`import numpy as np a = np.arange(16).reshape(4,4) #生成4行4列的数组 b = a[1][2] #输出6 c = a[1, 2] #同b d = a[1:2, 2:3] #输出[[6]] x = np.array([0, 1, 2, 1]) pri 阅读全文
posted @ 2024-10-28 11:58
VVV1
阅读(8)
评论(0)
推荐(0)
摘要:
`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(4) #输出[0, 0, 阅读全文
posted @ 2024-10-28 11:58
VVV1
阅读(11)
评论(0)
推荐(0)
摘要:
`import numpy as np a1 = np.array([1, 2, 3, 4]) #生成整型数组 a2 = a1.astype(float) a3 = np.array([1, 2, 3, 4], dtype=float) #浮点数 print(a1.dtype); print(a2. 阅读全文
posted @ 2024-10-28 11:57
VVV1
阅读(11)
评论(0)
推荐(0)
摘要:
`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) print("学号:3005")` 阅读全文
posted @ 2024-10-28 11:56
VVV1
阅读(16)
评论(0)
推荐(0)
摘要:
`def filter_non_unique(L): return [item for item in L if L.count(item) == 1] a=filter_non_unique([1, 2, 2, 3, 4, 4, 5]) print(a) print("学号:3005")` 阅读全文
posted @ 2024-10-28 11:56
VVV1
阅读(9)
评论(0)
推荐(0)
摘要:
`a = filter(lambda x: x>10,[1,11,2,45,7,6,13]) b = filter(lambda x: x.isalnum(),['abc', 'xy12', '***']) isalnum()是测试是否为字母或数字的方法 print(list(a)); print( 阅读全文
posted @ 2024-10-28 11:55
VVV1
阅读(12)
评论(0)
推荐(0)
摘要:
`import random x=random.randint(1e5,1e8) #生成一个随机整数 y=list(map(int,str(x))) #提出每位上的数字 z=list(map(lambda x,y: x%21 and y%20, [1,3,2,4,1],[3,2,1,2])) pri 阅读全文
posted @ 2024-10-28 11:54
VVV1
阅读(15)
评论(0)
推荐(0)
摘要:
`x1="abcde" x2=list(enumerate(x1)) for ind,ch in enumerate(x1): print(ch) print("学号:3005")` 阅读全文
posted @ 2024-10-28 11:54
VVV1
阅读(13)
评论(0)
推荐(0)
摘要:
`import numpy.random as nr x1=list(range(9,21)) nr.shuffle(x1) #shuffle()用来随机打乱顺序 x2=sorted(x1) #按照从小到大排序 x3=sorted(x1,reverse=True) #按照从大到小排序 x4=sort 阅读全文
posted @ 2024-10-28 11:53
VVV1
阅读(12)
评论(0)
推荐(0)
摘要:
`from ex2_12_2 import * print(factorial(6)) fib(300) print("学号:3005")` 阅读全文
posted @ 2024-10-28 11:51
VVV1
阅读(16)
评论(0)
推荐(0)
摘要:
` from math import * a=sin(3) #求正弦值 b=pi #常数π c=e #常数e d=radians(180) #把角度转换为弧度 print(a); print(b); print(c); print(d) print("学号:3005") ` 阅读全文
posted @ 2024-10-28 11:50
VVV1
阅读(8)
评论(0)
推荐(0)
摘要:
` from random import sample from numpy.random import randint a=sample(range(10),5) b=randint(0,10,5) print(a);print(b) print("学号:3005") ` 阅读全文
posted @ 2024-10-28 11:50
VVV1
阅读(17)
评论(0)
推荐(0)
摘要:
` import math import random import numpy.random as nr a=math.gcd(12,21) b=random.randint(0,2) c=nr.randint(0,2,(4,3)) print(a);print(b);print(c) print 阅读全文
posted @ 2024-10-28 11:49
VVV1
阅读(10)
评论(0)
推荐(0)
摘要:
` f=lambda x,y,z :xyz L=lambda x:[x2,x3,x**4] print(f(3,4,5));print(L(2)) print("学号:3005") ` 阅读全文
posted @ 2024-10-28 11:48
VVV1
阅读(12)
评论(0)
推荐(0)
摘要:
` def bifurcate_by(L,fn): return [[x for x in L if fn(x)], [x for x in L if not fn(x)]] s = bifurcate_by(['beep','boop','foo','bar'],lambda x:x[0]=='b 阅读全文
posted @ 2024-10-28 11:48
VVV1
阅读(19)
评论(0)
推荐(0)
摘要:
2.12.1 ` 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=" ") a,b=b,a+b print('%d!=%d'%(5,factorial(5)) 阅读全文
posted @ 2024-10-28 11:47
VVV1
阅读(27)
评论(0)
推荐(0)
摘要:
2.11.1 ` import string import random x=string.ascii_letters+string.digits y=''.join([random.choice(x) for i in range(1000)]) d=dict() for ch in y: d[c 阅读全文
posted @ 2024-10-28 11:45
VVV1
阅读(19)
评论(0)
推荐(0)
摘要:
`Dict={'age':18,'score':[98,97],'name':'Zhang','sex':'male'} for item in Dict: print(item) print(" ") for item in Dict.items(): print(item) print(" ") 阅读全文
posted @ 2024-10-28 11:44
VVV1
阅读(11)
评论(0)
推荐(0)
摘要:
`Dict={'age':18,'score':[98,97],'name':'Zhang','sex':'male'} print(Dict['age']) #输出18 print(Dict.get('age')) #输出18 print(Dict.get('address','Not Exist 阅读全文
posted @ 2024-10-28 11:43
VVV1
阅读(12)
评论(0)
推荐(0)
摘要:
` dict1={'Alice':'123','Beth':'456','Cecil':'abc'} print(dict1['Alice']) dict1['new']='Hello' dict1['Alice']='1234' dict2={'abc':123,456:78.9} print(d 阅读全文
posted @ 2024-10-28 11:42
VVV1
阅读(8)
评论(0)
推荐(0)
摘要:
` student = {'Tom','Jim','Mary','Tom','Jack','Rose'} print(student) a=set('abcdabc') print(a) print("学号:3005") ` 阅读全文
posted @ 2024-10-28 11:42
VVV1
阅读(9)
评论(0)
推荐(0)
摘要:
` T=('abc',12,3.45,'Python',2.789) print(T) print(T[-1]) print(T[1:3]) print("学号:3005") ` 阅读全文
posted @ 2024-10-28 11:41
VVV1
阅读(34)
评论(0)
推荐(0)
摘要:
import os fn=[filename for filename in os.listdir('D:/python xuexi/python work/数学建模课/!/《Python数学建模算法与应用》程序和数据/《Python数学建模算法与应用》程序和数据/02第2章 Python使用入门' 阅读全文
posted @ 2024-10-28 11:40
VVV1
阅读(12)
评论(0)
推荐(0)
摘要:
a=[[1,2,3],[4,5,6],[7,8,9]] d=[c for b in a for c in b] print(d) print("学号:2005") 阅读全文
posted @ 2024-10-28 11:37
VVV1
阅读(8)
评论(0)
推荐(0)
摘要:
L = ['abc', 12, 3.45, 'Python', 2.789] print(L) #输出完整列表 print(L[0]) #输出列表的第一个元素 L[0] = 'a' #修改列表的第一个元素 L[1:3] = ['b', 'Hello'] #修改列表的第二、三元素 print(L) L 阅读全文
posted @ 2024-10-28 11:34
VVV1
阅读(11)
评论(0)
推荐(0)
摘要:
` 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.count('t')]) b=n 阅读全文
posted @ 2024-10-28 11:31
VVV1
阅读(14)
评论(0)
推荐(0)
摘要:
`str1 = "Hello World!" print(str1) #输出字符串 print(str1[0:-1]) #输出第一个到倒数第2个的所有字符 print(str1[-1]) #输出字符串的最后一个字符 print(str1[2:5]) #输出从第三个开始到第五个的字符 print(st 阅读全文
posted @ 2024-10-28 11:26
VVV1
阅读(21)
评论(0)
推荐(0)
浙公网安备 33010602011771号