Myluzh Blog

Strive to become a dream architect.

Python numpy中ndarray与原生list对比

2023-7-13 myluzh Python

0x01 ndarray与list运行时长对比 import random import numpy as np import timeit a = [] for i in range(100000000): a.append(random.random()) def sum_list(): return sum(a) def sum_numpy(): b = np.array(a) return np.sum(b) time_list = timeit.timeit(sum_list, number=1) time_numpy = timeit.timeit(sum_numpy, number=1) print("List sum time:", time_list) print("Numpy sum time:", time_numpy) List sum time: 6.816154757 Numpy sum time: 4.999972694 0x02 ndarray的优势 (1)ndarray在存储数据的时候,数据...

阅读全文>>

标签: numpy ndarray

评论(0) (157)

Python matplotlib 绘制散点图/柱状图

2023-7-13 myluzh Python

0x01 散点图 import matplotlib.pyplot as plt import random # 生成数据 num_points = 1000 x = [random.uniform(0, 10) for i in range(1000)] y = [random.uniform(0, 10) for i in range(1000)] # 绘制散点图 plt.scatter(x, y, s=5, alpha=0.5) # 添加标题和标签 plt.title('Scatter Plot Example') plt.xlabel('X') plt.ylabel('Y') # 显示图形 plt.show() 0x02 柱状图 import matplotlib.pyplot as plt # 柱状图的数据 categories = ['A', 'B', 'C', 'D', 'E'] values = [15, 25, 10, 20, 30] # 创建一个新的图形 fig, ax = plt.subplots() # 绘制柱状图 ax.bar(categories, values) # 设置图形...

阅读全文>>

标签: python matplotlib 散点图 柱状图

评论(0) (130)

Python matplotlib 绘制折线图(多坐标系)

2023-7-13 myluzh Python

0x01 图像 0x02 代码 import matplotlib.pyplot as plt import random # 支持中文 from pylab import mpl mpl.rcParams['font.sans-serif'] = ['Arial Unicode MS'] mpl.rcParams['axes.unicode_minus'] = False # 用来解决不能使用汉字问题,需要导入matplotlib # 准备x y 数据 x = range(1, 31) y_hangzhou = [random.uniform(35, 42) for i in x] y_beijing = [random.uniform(34, 39) for i in x] # nrows/ncols设置成有几行几列的坐标系。返回fig:图对象,axes:返回相应数量的坐标系 fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(20, 8), dpi=50) axes[0].plot(x, y_hangzhou, color="b", ...

阅读全文>>

标签: python matplotlib

评论(0) (172)

Python matplotlib 绘制折线图(单坐标系)

2023-7-13 myluzh Python

0x01 图像 0x02 代码 import matplotlib.pyplot as plt import random # 支持中文 from pylab import mpl mpl.rcParams['font.sans-serif'] = ['Arial Unicode MS'] mpl.rcParams['axes.unicode_minus'] = False # 用来解决不能使用汉字问题,需要导入matplotlib # 准备x y 数据 x = range(1, 31) y_hangzhou = [random.uniform(35, 42) for i in x] y_beijing = [random.uniform(34, 39) for i in x] # 创建画布 plt.figure(figsize=(10, 5), dpi=70) # 绘制图像 plt.plot(x, y_hangzhou, color="b", linestyle='-', label='上海') plt.plot(x, y_beijing, color="r", linestyle...

阅读全文>>

标签: python matplotlib

评论(0) (117)

K8S笔记-集群架构组件详解

2023-7-12 myluzh Kubernetes

0x00 架构图 0x01 MasterNode *api server:集群对外的统一入口,以restful方式,交给etcd进行存储。 *scheduler:节点调度,选择node节点应用部署。 *controller-manager:处理集群常规后台任务,一个资源对应一个控制器。 *etcd:存储系统,用于保存集群相关数据。 0x02 WorkerNode *kubelet:master在worker创建的agent,管理本机容器生命周期的各种操作。 *kube-proxy:提供网络代理,负载均衡等操作。

阅读全文>>

标签: k8s 集群 架构 组件

评论(0) (145)

OpenVPN一键搭建脚本

2023-7-9 myluzh OpenVPN

0x01 install.sh #!/bin/bash # # https://github.com/hwdsl2/openvpn-install # # Based on the work of Nyr and contributors at: # https://github.com/Nyr/openvpn-install # # Copyright (c) 2022-2023 Lin Song <linsongui@gmail.com> # Copyright (c) 2013-2023 Nyr # # Released under the MIT License, see the accompanying file LICENSE.txt # or https://opensource.org/licenses/MIT exiterr() { echo "Error: $1" >&2; exit 1; } exiterr2() { exiterr "'apt-get install' failed."; } exiterr3() { exiterr "'y...

阅读全文>>

标签: openvpn

评论(0) (120)