创建递增数组
摘要:import numpy as nparr1 = np.arange(10)print("\n"+"从0开始到10之前结束:"+str(arr1))arr2 = np.arange(10,20)print("\n"+"从10开始到20之前结束:"+str(arr2))arr3 = np.arange
阅读全文
posted @
2025-11-25 17:48
偷懒的阿贤
阅读(6)
推荐(0)
创建同值数组
摘要:import numpy as np'''同值数组在创建时,已经设定为浮点型数组'''arr1 = np.zeros(10)print("\n" + "全0数组::" + str(arr1))arr2 = np.ones((1,3))print("\n" + "全1数组:" + str(arr2))
阅读全文
posted @
2025-11-25 17:48
偷懒的阿贤
阅读(7)
推荐(0)
创建指定数组
摘要:import numpy as nparr1 = np.array([11,1,1,1,])print("\n" + "创建一维数组--向量:" + str(arr1))arr2 = np.array([[1,1,1,1,1]])print("\n" + "创建二维数组--一行矩阵:" + str(
阅读全文
posted @
2025-11-25 17:47
偷懒的阿贤
阅读(3)
推荐(0)
数组维度
摘要:'''数组维度'''#(1)一维维度与二维数组'''不同维度的数组之间,从外形上的本质区别是一维数组使用1层中括号表示二维数组使用2层中括号表示三维数组使用3层中括号表示有些函数需要传入数组的形状参数,不同维度数组的形状参数为一维数组的形状参数形如:x或y二维数组的形状参数形如:(x,y)三维数组的
阅读全文
posted @
2025-11-11 14:46
偷懒的阿贤
阅读(9)
推荐(0)
数据类型
摘要:import numpy as np'''数据类型'''#(1)整数型数组和浮点型数组#创建整数型数组arr1 = np.array([1, 2, 3, 4, 5]) #元素若都是整数,则为整数型数组print("\n"+ "元素若都是整数,则为整数型数组:" + str(arr1))#创建浮点型数
阅读全文
posted @
2025-11-11 12:09
偷懒的阿贤
阅读(9)
推荐(0)
numpy介绍
摘要:用来数据计算的基础线性代数数学库 用来解决矩阵的运算 核心为ndarray,矢量化运算,广播机制 广播机制:两个矩阵在做运算时,会自动填充空缺的行列
阅读全文
posted @
2025-11-11 10:32
偷懒的阿贤
阅读(5)
推荐(0)
Python高阶和匿名函数 _ 脱了马甲也要认识
摘要:def calculate_and_print(num, calculator, formatter): result = calculator(num) formatter(num, result)def print_with_vertical_bar(num, result): print(f"
阅读全文
posted @
2025-10-31 21:33
偷懒的阿贤
阅读(3)
推荐(0)
Python测试(下) _ 高效率把bug揪出来
摘要:#导入测试内置模块import unittest#导入要测试的api,Student为类名from _oop import Studentfrom _oop import SmallStudent#需要继承unittest.TestCase,def函数必须用test_开头class MyTestCa
阅读全文
posted @
2025-10-31 21:02
偷懒的阿贤
阅读(5)
推荐(0)
Python测试(上)_ 不存在不写bug的程序员
摘要:#导入测试内置模块import unittest#导入要测试的apifrom _try_except import condition#需要继承unittest.TestCase,def函数必须用test_开头class MyTestCase(unittest.TestCase): def test
阅读全文
posted @
2025-10-31 20:36
偷懒的阿贤
阅读(6)
推荐(0)
Python异常处理 _ 程序炸之前,走一波预判
摘要:try: user_weight = float(input("请输入您的体重(单位:kg):")) user_height = float(input("请输入您的身高(单位:m):")) user_BMI = user_weight / (user_height ** 2)except Valu
阅读全文
posted @
2025-10-31 20:20
偷懒的阿贤
阅读(8)
推荐(0)
Python文件操作(下)_ 会写文件,程序便有了记忆
摘要:#在一个新的名字为“poem.txt”的文件里,写入以下内容:#我欲乘风归去#又恐琼楼玉宇with open("./poem.txt", "w", encoding="utf-8") as f: f.write("我欲乘风归去,\n又恐琼楼玉宇.\n")#任务2:在上面的poem.txt中文件结尾处
阅读全文
posted @
2025-10-31 17:58
偷懒的阿贤
阅读(5)
推荐(0)
Python文件操作(上)_ 会读文件,程序便有了眼睛
摘要:#方法一:读取文件f = open("./_math.py", "r", encoding="utf-8")content = f.readlines()for line in content: print(line)f.close()#方法二:读取文件,不用close()with open("./
阅读全文
posted @
2025-10-31 17:57
偷懒的阿贤
阅读(4)
推荐(0)
Python 类继承 _ 老鼠的儿子会打洞
摘要:class Employee: def __init__(self, name, id): self.name = name self.id = id def print_info(self): print(f"员工名字:{self.name},工号:{self.id}")class FullTim
阅读全文
posted @
2025-10-31 17:25
偷懒的阿贤
阅读(3)
推荐(0)
Python创建类(下)_ 当上帝的时刻到了
摘要:class Student: def __init__(self, name, student_id): self.name = name self.student_id = student_id self.grades = {"语文": 0, "数学":0, "英语": 0} def set_gr
阅读全文
posted @
2025-10-31 16:50
偷懒的阿贤
阅读(9)
推荐(0)
Python创建类(上)_ 没对象?实例化一个
摘要:class CuteCat: def __init__(self, cat_name, cat_age, _cat_color): self.name = cat_name self.age = cat_age self.color = _cat_colorcat1 = CuteCat("Jojo"
阅读全文
posted @
2025-10-31 16:13
偷懒的阿贤
阅读(3)
推荐(0)
8分钟搞懂面向对象编程
摘要:class Student: def __init__(self, study_name: int, school_name: str): self.name = study_name self.school_name = school_name def go_school(self, school
阅读全文
posted @
2025-10-31 11:54
偷懒的阿贤
阅读(2)
推荐(0)
自定义第三方模块
摘要:一、项目结构与命名 my_utils/├── src/│ └── my_utils/ # 真正的包目录(Python 3.3+ 可省略 __init__.py,但建议保留)│ ├── __init__.py│ └── calculator.py├── tests/│ └── test_calcul
阅读全文
posted @
2025-10-31 11:53
偷懒的阿贤
阅读(13)
推荐(0)
Python引入模块 _ 别人写的,拿来吧你
摘要:#使用import引入模块import statisticsprint("\n" + str(statistics.median([1,2,3,4,5,6,7,8,9])))#使用from xx import xx 直接引入模块中的函数from statistics import meanprint
阅读全文
posted @
2025-10-31 11:46
偷懒的阿贤
阅读(3)
推荐(0)