11 Python
文章平均质量分 55
Python
yangbocsu
少年一贯快马扬帆,道阻且长不转弯;
要盛大,要绚烂,要哗然;
要用理想的泰坦尼克,去撞现实的冰川;
要当烧赤壁的风,而非借鉴草船;
要为了一片海,就肯翻万山。
展开
-
Python Pip: 从基础到进阶
pip 是 Python 的官方包管理工具,全称为。方便开发者从 Python Package Index (PyPI) 或其他索引源安装、卸载和管理 Python 包。安装包: Pip 允许用户从 Python Package Index (PyPI) 或其他索引源安装 Python 包。PyPI 是一个官方的 Python 包仓库,拥有大量开源的 Python 库和工具包。卸载包: 用户可以使用 Pip 卸载不再需要的 Python 包,以保持 Python 环境的整洁。原创 2024-06-16 01:36:53 · 503 阅读 · 0 评论 -
如何使用 pip 卸载所有已安装的 Python 包?
通过以上步骤,我们可以方便地卸载所有已安装的 Python 包,为开发环境清理出一片新的天地。这对于解决包冲突或重新配置开发环境特别有用。希望这篇文章对你有所帮助!原创 2024-06-16 00:49:45 · 758 阅读 · 0 评论 -
Python
Lessons1 Hello, PythonHello, Python!Numbers and arithmetic in PythonOrder of operationsBuiltin functions for working with numbersYour Turn1 Hello, PythonThis course covers the key Python skills you’ll need so you can start using Python for data science.原创 2021-12-13 17:01:33 · 582 阅读 · 0 评论 -
Python字典的遍历
Python字典的遍历1 遍历字典的key2 遍历字典的value3 遍历字典的元素4 遍历字典的键值对1 遍历字典的key#1 遍历字典的keyinfo = {"name":"Tom","sex":"male","age":27}for k in info.keys(): print(k)2 遍历字典的value#2 遍历字典的valueinfo = {"name":"Tom","sex":"male","age":27}for k in info.keys(): p原创 2021-09-21 09:08:08 · 194 阅读 · 0 评论 -
Python赋值列表
Python赋值列表1.0 错误示范2.0 正确操作1.0 错误示范# Python赋值列表a = [1,2,3,4,5]b=aprint("修改前:")print("a=",a)print("b=",b)a[2]=99print("修改后:")print("a=",a)print("b=",b)直接用 = 赋值的话,不行,a和b都指向同一片内存区域,后面数据有所改动的话,一改全改;2.0 正确操作# Python赋值列表a = [1,2,3,4,5]b=a.copy原创 2021-09-17 15:24:53 · 2925 阅读 · 0 评论 -
Python时间复杂度
Python TimeComplexityhttps://wiki.python.org/moin/TimeComplexity原创 2021-07-23 13:07:43 · 220 阅读 · 0 评论 -
4种生成前n个整数列表的方法
4种生成前n个整数列表的方法# 4种生成前n个整数列表的方法计时import time# 1 循环连接def test_connect(num): l = [] for i in range(num): l = l + [i]# 2 append()方法def test_append(num): l = [] for i in range(num): l.append(i)# 3 列表推导式def test3(num):原创 2021-07-23 11:23:03 · 285 阅读 · 0 评论 -
“变位词”判断问题
“变位词”判断问题✧问题描述所谓“变位词”是指两个词之间存在组成字母的重新排列关系.如: heart和earth ,python和typhon为了简单起见,假设参与判断的两个词仅由小写字母构成,而且长度相等✧解题目标 :写一个bool函数,以两个词作为参数,返回这两个词是否变位词。可以很好展示同一问题的不同数量级算法解法1 : 逐字检查def anagramSolution1(s1,s2): alist = list(s2) pos1 = 0 stillOK = True whil原创 2021-07-23 11:09:31 · 181 阅读 · 0 评论 -
插入排序【Java版本、C版本、Python 版本】
对于基本有序的数组最好用稳定【Java】// yangbocsu 2021.05.23 民主楼package com.mashibing;public class InsertionSort { public static void main(String[] args) { int[] arr ={9,3,1,4,6,8,7,5,2}; print(arr); InsertionSort(arr); ...原创 2021-05-23 14:21:27 · 163 阅读 · 1 评论 -
冒泡排序【Java版本、C版本、Python 版本】
【Java版本】// yangbocsu 2021.05.23 民主楼package com.mashibing;public class BubbleSort { public static void main(String[] args) { int[] arr = {9,3,1,4,6,8,7,5,2}; print(arr); BubbleSort(arr); print(arr); } ...原创 2021-05-23 11:38:29 · 185 阅读 · 1 评论 -
选择排序【Java版本、C版本、Python 版本】
选择排序最简单但是最没用的排序算法,也有优化空间;时间复杂度是O(n^2) 还不稳定;如何计算时间和空间复杂度算法的验证-随机数据生成器、对数器写算法程序的哲学原创 2021-04-08 16:32:47 · 127 阅读 · 0 评论 -
sklearn数据集之breast_cancer
sklearn数据集之breast_cancer0 导入相关库from sklearn.datasets import load_breast_cancerfrom sklearn.model_selection import train_test_split1 数据分析cancer.keys()dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names', 'filename'])可当作字典原创 2021-05-17 14:56:12 · 5054 阅读 · 0 评论 -
Python 批量化新建文件夹
Python 批量创建文件夹因经常有新建多个文件夹的需要,就想到了用python 来实现,然后做到了,目前支持单一创建和批量化创建。#yangbocsu 2021.05.12import os#path = "E:\Study\研究生--课程\【算法与数据结构】\面向对象程序设计--Java语言--翁恺"#file_name = ['第1周 类与对象','第2周 对象交互','第3周 对象容器','第4周 继承与多态','第5周 设计原则','第6周 抽象与接口','第7周 控制反原创 2021-05-12 22:15:35 · 832 阅读 · 0 评论 -
Python 自动下载论文
目录0 导入相关的库1 获取URL信息2 设置请求头 3获取相关论文的DOI列表4构建sci-hub下载链接5 检索及下载0 导入相关的库# 导入所需模块import requestsimport reimport osfrom urllib.request import urlretrieve1 获取URL信息# 获取URL信息def get_url(key): url = 'https://xueshu.baidu.co...原创 2021-05-12 20:16:20 · 441 阅读 · 0 评论 -
通过使用 print()函数和三引号‘‘‘,点击“代码实现”在右边区域书写代码将“丘比特之心“图案在终端展示输出。
print(''' *** *** ********* ********* ************ ************ ************* ************* ************** ************** *************** *************** ...原创 2021-05-12 18:24:02 · 372 阅读 · 0 评论 -
KNeighborsClassifier()
Init signature:KNeighborsClassifier( n_neighbors=5, *, weights='uniform', algorithm='auto', leaf_size=30, p=2, metric='minkowski', metric_params=None, n_jobs=None, **kwargs,)Docstring: Classifier implementin.原创 2021-05-04 15:40:52 · 1328 阅读 · 0 评论 -
pd.plotting.scatter_matrix()
pd.plotting.scatter_matrix()Signature:pd.plotting.scatter_matrix( frame, alpha=0.5, figsize=None, ax=None, grid=False, diagonal='hist', marker='.', density_kwds=None, hist_kwds=None, range_padding=0.05, **kwa原创 2021-05-04 12:53:35 · 1377 阅读 · 0 评论 -
fig.add_subplot()
Signature: fig.add_subplot(*args, **kwargs)Docstring:Add an `~.axes.Axes` to the figure as part of a subplot arrangement.Call signatures:: add_subplot(nrows, ncols, index, **kwargs) add_subplot(pos, **kwargs) add_subplot(ax) add_subplo...原创 2021-05-01 22:40:49 · 2667 阅读 · 0 评论 -
Python画3D
lz# -*- coding: utf-8 -*-from matplotlib import pyplot as plt#设置图表刻度等格式from matplotlib.ticker import MultipleLocator, FormatStrFormatter from mpl_toolkits.mplot3d import Axes3Dimport numpy as np#make_pic的内置函数,用来在图像里面不断添加立方体def box(ax,x, y, z,...原创 2021-05-01 22:35:51 · 762 阅读 · 0 评论 -
tick能见度
import matplotlib.pyplot as pltimport numpy as npx = np.linspace(-3,3,50)y = 0.1*xplt.figure()#开一张画布plt.plot(x,y,linewidth =10,zorder =1)#绘画plt.ylim(-2,2)ax = plt.gca()ax.spines['right'].set_color('none')ax.spines['top'].set_color('none')...原创 2021-05-01 21:44:20 · 113 阅读 · 0 评论 -
Python直角坐标系画图
Python直角坐标系画图# coding:utf8 import matplotlib.pyplot as pltimport numpy as np # 先获取一个图表fig = plt.figure() # 设置x,y坐标轴的刻度显示范围plt.xlim(-7, 7)plt.ylim(0, 7) # 抛物线X1 = np.linspace(-5, 5, 50) # -5 ~ 5 之间生成50个点Y1 = 0.25 * X1 ** 2plt.plot(X1, Y1,原创 2021-05-01 12:54:02 · 7078 阅读 · 0 评论 -
plt.plot()
Signature: plt.plot(*args, scalex=True, scaley=True, data=None, **kwargs)Docstring:Plot y versus x as lines and/or markers.Call signatures:: plot([x], y, [fmt], *, data=None, **kwargs) plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)The.原创 2021-04-29 22:53:08 · 348 阅读 · 0 评论 -
Matplotlib: Visualization with Python
Matplotlib: Visualization with PythonMatplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. Matplotlib makes easy things easy and hard things possible.CreateDeveloppubli...原创 2021-04-29 22:49:27 · 206 阅读 · 0 评论 -
plt.annotate()
Signature: plt.annotate(text, xy, *args, **kwargs)Docstring:Annotate the point *xy* with text *text*.In the simplest form, the text is placed at *xy*.Optionally, the text can be displayed in another position *xytext*.An arrow pointing from the text.原创 2021-04-29 22:36:10 · 611 阅读 · 0 评论 -
plt.scatter()
Signature:plt.scatter( x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, *, edgecolors=None, plotnonfinite=False, data=None, **kwarg.原创 2021-04-29 22:24:06 · 229 阅读 · 0 评论 -
Matplotlib Python3 legend图例
MatplotlibPython3legend图例import matplotlib.pyplot as pltimport numpy as np#matplotlib画图中中文显示会有问题,需要这两行设置默认字体plt.rcParams['font.sans-serif']=['SimHei']plt.rcParams['axes.unicode_minus'] = False#数据生成x = np.linspace(-3,3,50)y1 = 2*x+1y2 = x**2..原创 2021-04-29 22:15:18 · 199 阅读 · 0 评论 -
plt.legend()
Signature: plt.legend(*args, **kwargs)Docstring:Place a legend on the Axes.Call signatures:: legend() legend(labels) legend(handles, labels)The call signatures correspond to these three different ways to usethis method:**1. Automatic.原创 2021-04-29 22:10:34 · 1115 阅读 · 0 评论 -
plt.xticks()
Signature: plt.xticks(ticks=None, labels=None, **kwargs)Docstring:Get or set the current tick locations and labels of the x-axis.Pass no arguments to return the current values without modifying them.Parameters----------ticks : array-like, optional.原创 2021-04-29 22:05:27 · 3432 阅读 · 0 评论 -
matplotlib 画坐标
matplotlib 画坐标import matplotlib.pyplot as pltimport numpy as np#数据生成x = np.linspace(-3,3,50)y1 = 2*x+1y2 = x**2plt.figure()plt.plot(x,y1) #也可以plt.plot(y,x)plt.plot(x,y2,linewidth = 1,linestyle = '--',color='red') #也可以plt.plot(y,x)plt....原创 2021-04-29 22:03:50 · 380 阅读 · 0 评论 -
plt.plot()
Signature: plt.plot(*args, scalex=True, scaley=True, data=None, **kwargs)Docstring:Plot y versus x as lines and/or markers.Call signatures:: plot([x], y, [fmt], *, data=None, **kwargs) plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)Th原创 2021-04-29 21:25:48 · 379 阅读 · 0 评论 -
plt.figure()
Signature:plt.figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True, FigureClass=<class 'matplotlib.figure.Figure'>, clear=False, **kwargs,)Docstring:Create a new figure, or activate an exis.原创 2021-04-29 21:19:22 · 245 阅读 · 0 评论 -
A 跳高【中兴捧月神算师-算法精英挑战赛-比特派第一场】
题目描述在新的一年,牛牛想跳得更高。牛牛本身可以跳高{h}h米。同时牛牛有{n}n颗跳高弹,使用第{i}i颗跳高弹可以使牛牛跳高高度增加a_iai米,且跳高弹的效果是可以叠加的,也就是说如果牛牛使用多颗跳高弹,那么他的跳高高度将会增加这些跳高弹单个效果的和。每颗跳高弹只能使用一次。请问牛牛最少需要使用多少个跳高弹,才能让牛牛的高度至少是{u}u米高呢?数据保证答案存在。输入描述:输出描述:输出一个整数,表示答案。示例1输入3 2 51 3 2.原创 2021-04-24 21:37:25 · 243 阅读 · 0 评论 -
2021-04-23
题目描述tjc有一个序列长度为nn的a[1...n]a[1...n],定义一个数a[i]a[i]的权值为它在数列里出现的次数乘上这个数,tjc想知道所有数里权值最大的数的权值的大小输入描述:tjc会给你一个长度为nn的数列输出描述:输出权值最大的数的权值为答案示例1输入51 2 2 1 1输出4备注:1 <= n <= 100000 1<=n<=1000001 <= a[i] ...原创 2021-04-23 21:19:45 · 144 阅读 · 0 评论 -
压缩字符串【Python百题大冲关】
压缩字符串挑战介绍实现一个算法来压缩一个字符串。压缩的要求如下:需要判断压缩能不能节省空间,仅在压缩后字符串比原字符串长度更短时进行压缩。 压缩的格式是将连续相同字符替换为字符+数字形式,例如"AAABCCDDDD"变为"A3BC2D4"。挑战内容本次挑战中,你需要在compress_str.py文件中补充函数compress的空缺部分。compress函数接受一个参数,string用于指定传入的字符串; compress函数输出一个字符串。你需要补充com...原创 2021-04-23 14:57:32 · 514 阅读 · 1 评论 -
确定字符串是否是另一个的旋转【Python百题大冲关】
确定字符串是否是另一个的旋转挑战介绍实现一个算法来识别一个字符串s2是否是另一个字符串s1的旋转。旋转的解释如下:如果将s1从某个位置断开,拆分成两个字符串(可能有一个为空字符串),再将这两个字符串调换顺序后拼接起来,能够得到s2,那么说字符串s2是字符串s1的旋转。挑战内容本次挑战中,你需要在rotation.py文件中补充函数is_substring及函数is_rotation的空缺部分。 is_substring函数接受两个参数,s...原创 2021-04-23 14:14:35 · 379 阅读 · 0 评论 -
确定字符串是否是另一个的排列【【Python百题大冲关】】
确定字符串是否是另一个的排列挑战介绍实现一个算法来识别一个字符串str2是否是另一个字符串str1的排列。排列的解释如下:如果将str1的字符拆分开,重新排列后再拼接起来,能够得到str2,那么就说字符串str2是字符串str1的排列。挑战内容本次挑战中,你需要在permutation.py文件中补充函数is_permutation的空缺部分。is_permutation函数接受两个参数,str1,str2用于指定传入的两个字符串; is_p...原创 2021-04-23 13:49:48 · 302 阅读 · 0 评论 -
确定字符串是否包含唯一字符【Python百题大冲关】
确定字符串是否包含唯一字符挑战介绍实现一个算法来识别一个字符串的字符是否是唯一的。挑战内容本次挑战中,你需要在unique_chars.py文件中补充函数has_unique_chars的空缺部分。has_unique_chars函数接受一个参数,string用于指定传入的字符串; has_unique_chars函数输出一个布尔值,即True或者False。你需要补充has_unique_chars函数,使其可以识别传入的string字符串的字...原创 2021-04-23 13:15:10 · 487 阅读 · 0 评论 -
A+B 问题【OJ 示例题目】
A+B 问题【OJ 示例题目】题目描述欢迎开启算法 OJ 题的大门,本题为经典的A+BA+B入门题,我们会以此题为示例介绍蓝桥云课 OJ 系统的正确使用方法。问题描述输入两个正整数A,BA,B,请你计算A+BA+B,并输出。根据题目描述,你需要做以下事情:编写一个程序,使用标准输入来输入两个整数AA和BB,然后把A+BA+B的结果使用标准输出来输出。你可以滚动到本页面下方查看题目的示例输入和输出,这将极大地帮助你理解和完成题目。那么,什么是标准输入和输出呢?...原创 2021-04-23 12:40:41 · 3357 阅读 · 3 评论 -
MP3 储存【蓝桥杯填空题示例题目】
MP3 储存【蓝桥杯填空题示例题目】题目描述本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。如果一个 MP3 文件占用磁盘的大小是 4MB,小蓝的硬盘还剩下 100GB 的空间,请问他还可以放多少个这样的 MP3 文件?正确解法本题正确答案为2560025600,只需要在代码中使用输出语句输出即可,各语言示例如下:Pythonimport osimport sys# 请在此输入您的代码a = int(100*1024/4)print..原创 2021-04-23 11:30:01 · 261 阅读 · 0 评论 -
Linux 基础入门
Linux 基础入门本课程教你如何熟练地使用 Linux,本实验中通过在线动手实验的方式学习 Linux 常用命令,用户与权限管理,目录结构与文件操作,环境变量,计划任务,管道与数据流重定向等基本知识点。目录Linux 基础入门实验任务先学知识课程难度面向用户实验 1 Linux 系统简介一、实验介绍1.1 实验内容1.2 知识点二、实验内容linux 为何物2.1 Linux 历史简介2.2 Linux 重要人物2.3 Linux 与原创 2021-04-22 22:58:46 · 315 阅读 · 0 评论