摘要:
import cvxpy as cp import networkx as nx import numpy as np Adjt = [(1,2,18),(1,5,15),(2,3,20),(2,4,60),(2,5,12), (3,4,30),(3,5,18),(4,6,10),(5,6,15)] 阅读全文
posted @ 2024-10-27 23:58
世梦
阅读(28)
评论(0)
推荐(0)
摘要:
import networkx as nx import numpy as np Adjt = [(1,2,20), (1,5,15), (2,3,20), (2,4,60), (2,5,25), (3,4,30), (3,5,18), (5,6,15)] G = nx.Graph() G.add_ 阅读全文
posted @ 2024-10-27 23:58
世梦
阅读(21)
评论(0)
推荐(0)
摘要:
import numpy as np import pandas as pd import cvxpy as cp import networkx as nx import matplotlib.pyplot as plt df = pd.read_excel('F:\python数学建模与算法\源 阅读全文
posted @ 2024-10-27 23:57
世梦
阅读(19)
评论(0)
推荐(0)
摘要:
import numpy as np import cvxpy as cp import networkx as nx n = 6 A=np.zeros((n,n)) A[0,[1,2]]=[2,7] A[1,2:5]=[4,6,8] A[2,[3,4]]=[1,3] A[3,[4,5]]=[1,6 阅读全文
posted @ 2024-10-27 23:57
世梦
阅读(42)
评论(0)
推荐(0)
摘要:
import numpy as np import pandas as pd import cvxpy as cp import networkx as nx import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['Time 阅读全文
posted @ 2024-10-27 23:56
世梦
阅读(16)
评论(0)
推荐(0)
摘要:
import numpy as np import pandas as pd import cvxpy as cp import networkx as nx import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['Time 阅读全文
posted @ 2024-10-27 23:56
世梦
阅读(11)
评论(0)
推荐(0)
摘要:
import numpy as np import pandas as pd import cvxpy as cp import networkx as nx import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['Time 阅读全文
posted @ 2024-10-27 23:56
世梦
阅读(31)
评论(0)
推荐(0)
摘要:
import cvxpy import cvxpy as cp import numpy as np import pandas as pd from scipy.optimize import minimize import sympy as sp sp.init_printing(use_uni 阅读全文
posted @ 2024-10-27 23:55
世梦
阅读(19)
评论(0)
推荐(0)
摘要:
linprog from scipy.optimize import linprog c=[0,0,3,2] A=[[-1,-1,0,0],[0,0,-1,-1],[3,0,2,0],[0,3,0,2],[100,90,80,70]] b=[[-30],[-30],[120],[48],[10000 阅读全文
posted @ 2024-10-27 23:54
世梦
阅读(18)
评论(0)
推荐(0)
摘要:
import numpy as np import math from scipy.optimize import minimize, Bounds def func(x): return sum(math.sqrt(x[i]) for i in range(100)) def con(x): re 阅读全文
posted @ 2024-10-27 23:53
世梦
阅读(13)
评论(0)
推荐(0)
摘要:
import cvxpy as cp import numpy as np import pandas as pd import sympy as sp sp.init_printing(use_unicode=True) import matplotlib.pyplot as plt plt.rc 阅读全文
posted @ 2024-10-27 23:52
世梦
阅读(14)
评论(0)
推荐(0)
摘要:
import cvxpy as cp import numpy as np import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['Times New Roman + SimSun + WFM Sans SC'] plt.r 阅读全文
posted @ 2024-10-27 23:51
世梦
阅读(16)
评论(0)
推荐(0)
摘要:
import numpy as np import pandas as pd import sympy as sp sp.init_printing(use_unicode=True) import matplotlib.pyplot as plt plt.rcParams['font.sans-s 阅读全文
posted @ 2024-10-27 23:50
世梦
阅读(22)
评论(0)
推荐(0)
摘要:
import numpy as np import pandas as pd import sympy as sp sp.init_printing(use_unicode=True) import matplotlib.pyplot as plt plt.rcParams['font.sans-s 阅读全文
posted @ 2024-10-27 23:49
世梦
阅读(19)
评论(0)
推荐(0)
摘要:
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[ch] 阅读全文
posted @ 2024-10-27 23:47
世梦
阅读(26)
评论(0)
推荐(0)
摘要:
Dict={'age':18,'score':[98,9],'name':'Zhang','sex':'male'} for item in Dict: print(item) print(" ") for item in Dict.items(): print(item) print(" ") f 阅读全文
posted @ 2024-10-27 23:46
世梦
阅读(15)
评论(0)
推荐(0)
摘要:
Dict={'age':18,'score':[98,97],'name':'Zhang','sex':'male'} print(Dict['age']) print(Dict.get('age')) print(Dict.get('address','NotExists.')) print(Di 阅读全文
posted @ 2024-10-27 23:46
世梦
阅读(21)
评论(0)
推荐(0)
摘要:
dict1 ={'Alice':'123','Reth':'456','Cecil':'abc'} print(dict1['Alice']) dict1['new']='Hello' dict1['Alice']='1234' dict2={'abc':123,456:78.9} print(di 阅读全文
posted @ 2024-10-27 23:45
世梦
阅读(11)
评论(0)
推荐(0)
摘要:
student={'Tom','Jim','Mary','Tom','Jack','Rose'} print(student) a=set('abcdabc') print(a) 阅读全文
posted @ 2024-10-27 23:44
世梦
阅读(15)
评论(0)
推荐(0)
摘要:
T=('abc',12,3.45,'Python',2.789) print(T) print(T[-1]) print(T[1:3]) 阅读全文
posted @ 2024-10-27 23:44
世梦
阅读(15)
评论(0)
推荐(0)
摘要:
-- coding: utf-8 -- """ Created on Tue Sep 17 19:40:05 2024 @author: 朱尧 """ from numpy.random import randint import numpy as np a = randint(10,20,16) 阅读全文
posted @ 2024-10-27 23:43
世梦
阅读(19)
评论(0)
推荐(0)
摘要:
-- coding: utf-8 -- """ Created on Tue Sep 17 19:39:40 2024 @author: 朱尧 """ 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-27 23:42
世梦
阅读(13)
评论(0)
推荐(0)
摘要:
-- coding: utf-8 -- """ Created on Tue Sep 17 19:37:31 2024 @author: 朱尧 """ L = ['abc', 12, 3.45, 'Python', 2.789] print(L) print(L[0]) L[0] = 'a' L[1 阅读全文
posted @ 2024-10-27 23:41
世梦
阅读(14)
评论(0)
推荐(0)
摘要:
with open('统计2.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 in L2] pr 阅读全文
posted @ 2024-10-27 23:39
世梦
阅读(20)
评论(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']) a.loc['a 阅读全文
posted @ 2024-10-27 23:39
世梦
阅读(23)
评论(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] d2=d[4:] dd=pd.concat([d1,d2]) s1=d 阅读全文
posted @ 2024-10-27 23:38
世梦
阅读(15)
评论(0)
推荐(0)
摘要:
import pandas as pd a=pd.read_csv("统计2.2.csv",usecols=range(1,5)) b=pd.read_excel("统计2.2.xlsx","Sheet2",usecols=range(1,5)) 阅读全文
posted @ 2024-10-27 23:37
世梦
阅读(16)
评论(0)
推荐(0)
摘要:
程序文件ex2_38_1.py import pandas as pd import numpy as np dates=pd.date_range(start='20191101', end='20191124', freq='D') a1=pd.DataFrame(np.random.randn 阅读全文
posted @ 2024-10-27 23:36
世梦
阅读(16)
评论(0)
推荐(0)
摘要:
程序文件ex2_37.py 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, 阅读全文
posted @ 2024-10-27 23:35
世梦
阅读(24)
评论(0)
推荐(0)
摘要:
程序文件ex2_36.py import numpy as np a = np.eye(4) b = np.rot90(a) c, d = np.linalg.eig(b) print('特征值为:', c) print('特征向量为:\n', d) 阅读全文
posted @ 2024-10-27 23:35
世梦
阅读(17)
评论(0)
推荐(0)
摘要:
程序文件ex2_35.py 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)) 阅读全文
posted @ 2024-10-27 23:34
世梦
阅读(27)
评论(0)
推荐(0)
摘要:
程序文件ex2_34.py 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.solv 阅读全文
posted @ 2024-10-27 23:33
世梦
阅读(21)
评论(0)
推荐(0)
摘要:
程序文件ex2_33.py 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 阅读全文
posted @ 2024-10-27 23:32
世梦
阅读(22)
评论(0)
推荐(0)
摘要:
程序文件ex2_31.py 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 阅读全文
posted @ 2024-10-27 23:30
世梦
阅读(15)
评论(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) c3 = np.sum(a, axis = 1, keepdims = True) pri 阅读全文
posted @ 2024-10-27 23:30
世梦
阅读(18)
评论(0)
推荐(0)
摘要:
import numpy as np a = np.arange(16).reshape(4, 4) b = np.vsplit(a, 2) print('行分割: \n', b[0], '\n', b[1]) c = np.hsplit(a, 4) print('列分割:: \n', c[0], 阅读全文
posted @ 2024-10-27 23:29
世梦
阅读(16)
评论(0)
推荐(0)
摘要:
import numpy as np a = np.arange(16).reshape(4,4) b = np.floor(5 * np.random.random((2, 4))) c = np.ceil(6 * np.random.random((4, 2))) d = np.vstack([ 阅读全文
posted @ 2024-10-27 23:28
世梦
阅读(17)
评论(0)
推荐(0)
摘要:
import numpy as np a = np.arange(16).reshape(4,4) b = a[1][2] c= a[1, 2] d = a[1:2, 2:3] x = np.array([0, 1, 2, 1]) print(a[x == 1]) 阅读全文
posted @ 2024-10-27 23:27
世梦
阅读(15)
评论(0)
推荐(0)
摘要:
import numpy as np a = np.ones(4, dtype= int) b = np.ones((4,), dtype= int) c = np.ones((4,1)) d = np.zeros(4) e = np.empty(3) f = np.eye(3) g = np.ey 阅读全文
posted @ 2024-10-27 23:26
世梦
阅读(18)
评论(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.dtype); print(a3.d 阅读全文
posted @ 2024-10-27 23:26
世梦
阅读(22)
评论(0)
推荐(0)
摘要:
s1 = [str(x) for x, y in zip(['v'] * 4, range(1, 5))] s2 = list(zip('abcd', range(4))) print(s1); print(s2) 阅读全文
posted @ 2024-10-27 23:25
世梦
阅读(15)
评论(0)
推荐(0)
摘要:
def filter_non_unique(L): return [item for item in L if L.count(item) == 1] a = filter_non_unique([1, 2, 3, 4, 5]) print(a) 阅读全文
posted @ 2024-10-27 23:24
世梦
阅读(24)
评论(0)
推荐(0)
摘要:
a = filter(lambda x: x > 10, [1, 11, 2, 45, 7, 6, 13]) b = filter(lambda x: x.isalnum(), ['abc', 'xy12', '***']) print(list(a)); print(list(b)) 阅读全文
posted @ 2024-10-27 23:23
世梦
阅读(26)
评论(0)
推荐(0)
摘要:
import random x = random.randint(1e5, 1e8) y = list(map(int, str(x))) z = list(map(lambda x, y: x%2 == 1 and y%2 == 0, [1, 3, 2, 4, 1], [3, 2,1, 2])) 阅读全文
posted @ 2024-10-27 23:22
世梦
阅读(14)
评论(0)
推荐(0)
摘要:
x1 = "abcde" x2 = list(enumerate(x1)) for ind, ch in enumerate(x1): print(ch) 阅读全文
posted @ 2024-10-27 23:21
世梦
阅读(32)
评论(0)
推荐(0)
摘要:
import numpy.random as nr x1 = list(range(9,21)) nr.shuffle(x1) x2 = sorted(x1) x3 = sorted(x1, reverse=True) x4 = sorted(x1, key = lambda item: len(s 阅读全文
posted @ 2024-10-27 23:20
世梦
阅读(24)
评论(0)
推荐(0)
摘要:
from ex2_12_2 import * print(factorial(6)) fib(300) 阅读全文
posted @ 2024-10-27 23:19
世梦
阅读(19)
评论(0)
推荐(0)
摘要:
from math import * a = sin(3) b = pi c = e d = radians(180) print(a); print(b); print(c); print(d) 阅读全文
posted @ 2024-10-27 23:19
世梦
阅读(17)
评论(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) 阅读全文
posted @ 2024-10-27 23:18
世梦
阅读(19)
评论(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)) pr int(a); print(b); pr 阅读全文
posted @ 2024-10-27 23:17
世梦
阅读(21)
评论(0)
推荐(0)
摘要:
f = lambda x, y, z: x * y * z L = lambda x: [x2, x3, x**4] print(f(3, 4, 5)); print(L(2)) 阅读全文
posted @ 2024-10-27 23:16
世梦
阅读(11)
评论(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] 阅读全文
posted @ 2024-10-27 23:15
世梦
阅读(16)
评论(0)
推荐(0)
摘要:
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'%( 阅读全文
posted @ 2024-10-27 23:14
世梦
阅读(12)
评论(0)
推荐(0)
摘要:
import string, random, collections x = string.ascii_letters + string.digits y = ' '.join([random.choice(x) for i in range(1000)]) count = collections. 阅读全文
posted @ 2024-10-27 23:13
世梦
阅读(13)
评论(0)
推荐(0)
摘要:
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-27 23:11
世梦
阅读(27)
评论(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) p 阅读全文
posted @ 2024-10-27 23:10
世梦
阅读(18)
评论(0)
推荐(0)
摘要:
Dict = {'age': 18, 'score': [98, 97], 'name': 'zhang', 'sex': 'male'} try: print(Dict['age']) print(Dict.get('age')) print(Dict.get('address', 'Not Ex 阅读全文
posted @ 2024-10-27 23:08
世梦
阅读(48)
评论(0)
推荐(0)
摘要:
dict1 = {'Alice': '123', 'Beth': '456', 'Cecil': 'abc'} print(dict1['Alice']) dict1['new'] = 'Hello' dict1['Alice'] = '1234' dict2 = {'abc': 123, 456: 阅读全文
posted @ 2024-10-27 23:07
世梦
阅读(15)
评论(0)
推荐(0)
摘要:
student = {'Tom', 'Jim', 'Mary', 'Tom', 'Jack', 'Rose'} print(student) a = set('abcdabc') print(a) 阅读全文
posted @ 2024-10-27 23:06
世梦
阅读(19)
评论(0)
推荐(0)
摘要:
T = ('abc', 12, 3.45, 'python', 2.789) print(T) print(T[-1]) print(T[1:3]) 阅读全文
posted @ 2024-10-27 23:05
世梦
阅读(19)
评论(0)
推荐(0)
摘要:
import os folder_path = (r'D:\Programs\Python\Python37' ) fn = [filename for filename in os.listdir(folder_path) if filename.endswith(('.exe', '.py')) 阅读全文
posted @ 2024-10-27 23:02
世梦
阅读(20)
评论(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(3029) 阅读全文
posted @ 2024-10-27 23:00
世梦
阅读(39)
评论(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[2:4] = [] print(L) print(3029) 阅读全文
posted @ 2024-10-27 22:57
世梦
阅读(13)
评论(0)
推荐(0)
摘要:
import numpy as np a = [] with open('data2.txt', 'r', encoding='utf-8') as f: for i, s in enumerate(f): counts = (s.count('a'), s.count('c'), s.count( 阅读全文
posted @ 2024-10-27 22:55
世梦
阅读(9)
评论(0)
推荐(0)

浙公网安备 33010602011771号