摘要:
from numpy.random import randint import numpy as np a = randint(10,20,16) ma = max(a) ind1 = [index for index,value in enumerate(a) if value == ma] in 阅读全文
posted @ 2024-10-15 16:38
方~~
阅读(18)
评论(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("学号:3008") a=[[1,2,3],[4,5,6],[7,8,9 阅读全文
posted @ 2024-10-15 16:35
方~~
阅读(25)
评论(0)
推荐(0)
摘要:
'''首先先定义一个列表,列表是写在[]里,用逗号隔开的,元素是可以改变的列表的截取语法结构是:变量[头下标:尾下标]'''L = ['abc',12,3.45,'python',2.789]#输出完整列表print(L)#输出列表的第一个元素print(L[0])#将列表的第一个元素修改为‘a’L 阅读全文
posted @ 2024-10-15 16:34
方~~
阅读(17)
评论(0)
推荐(0)
摘要:
import numpy as np a = [] with open('data2_2.txt') as f: for(i,s) in enumerate(f): a.append([a.count('a'),a.count('c'), a.count('g'),a.count('t')]) b 阅读全文
posted @ 2024-10-15 16:32
方~~
阅读(9)
评论(0)
推荐(0)
摘要:
python中字符串用单引号或者双引号括起来 访问字符串时,采用方式: 变量[头下标:尾下标] str1= "Hello word!" print(str1) print(str1[0:-1]) print(str1[-1]) print(str1[2:5]) print(str1[2:]) pri 阅读全文
posted @ 2024-10-15 16:30
方~~
阅读(23)
评论(0)
推荐(0)
摘要:
import matplotlib.pyplot as plt import numpy as np import cvxpy as cp x=cp.Variable(6,pos=True) obj=cp.Minimize(x[5]) a1=np.array([0.025, 0.015, 0.055 阅读全文
posted @ 2024-10-15 14:42
方~~
阅读(23)
评论(0)
推荐(0)
摘要:
initial_costs = [2.5, 2.6, 2.8, 3.1] salvage_values = [2.0, 1.6, 1.3, 1.1] maintenance_costs = [0.3, 0.8, 1.5, 2.0] dp = [[float('inf')] * 2 for _ in 阅读全文
posted @ 2024-10-14 23:56
方~~
阅读(12)
评论(0)
推荐(0)
摘要:
import heapq def prim(graph, start): num_nodes = len(graph) visited = [False] * num_nodes min_heap = [(0, start, -1)] mst_cost = 0 mst_edges = [] whil 阅读全文
posted @ 2024-10-14 23:55
方~~
阅读(12)
评论(0)
推荐(0)
摘要:
edges = [ ("Pe", "T", 13), ("Pe", "N", 68), ("Pe", "M", 78), ("Pe", "L", 51), ("Pe", "Pa", 51), ("T", "N", 68), ("T", "M", 70), ("T", "L", 6 阅读全文
posted @ 2024-10-14 23:52
方~~
阅读(13)
评论(0)
推荐(0)
摘要:
import numpy as np demands = [40, 60, 80] max_production = 100 total_demand = sum(demands) dp = np.full((4, total_demand + 1), float('inf')) dp[0][0] 阅读全文
posted @ 2024-10-14 23:49
方~~
阅读(24)
评论(0)
推荐(0)