摘要: import torch import torch.nn as nn import torch.optim as optim import numpy as np 1. 配置参数(初学者友好版) 设备配置:优先使用GPU,没有则用CPU device = torch.device('cuda' if 阅读全文
posted @ 2025-12-04 10:19 HeDesongfuqin 阅读(2) 评论(0) 推荐(0)
摘要: import os import random import numpy as np import matplotlib.pyplot as plt from PIL import Image, ImageDraw, ImageFont import torch import torch.nn as 阅读全文
posted @ 2025-10-30 22:16 HeDesongfuqin 阅读(12) 评论(0) 推荐(0)
摘要: 在深度学习领域,卷积神经网络(CNN)凭借其在图像识别、计算机视觉等任务中的卓越表现,成为新手入门深度学习时绕不开的重要知识点。而 PyTorch 作为一款简洁灵活的深度学习框架,为理解和实现 CNN 提供了极大的便利。通过对相关 PyTorch 深度学习资料的学习,我对卷积神经网络的原理有了初步且 阅读全文
posted @ 2025-10-15 21:02 HeDesongfuqin 阅读(20) 评论(0) 推荐(0)
摘要: import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader from torchvision import datasets, transforms im 阅读全文
posted @ 2025-10-15 20:53 HeDesongfuqin 阅读(21) 评论(0) 推荐(0)
摘要: pygame小游戏 import pygame import random 初始化pygame pygame.init() 定义颜色 white = (255, 255, 255) black = (0, 0, 0) red = (213, 50, 80) green = (0, 255, 0) b 阅读全文
posted @ 2025-06-21 16:06 HeDesongfuqin 阅读(13) 评论(0) 推荐(0)
摘要: 在数据科学和科学计算领域,python因为其丰富的库生态系统而成为首选语言,例如其中的numpy,scipy,pandas,matplotlib构成了python科学计算的核心工具。 接下来我将报告这四个库的基本用法和实际应用。 首先是numpy,它是python中科学计算的基础库,提供了高效的多维 阅读全文
posted @ 2025-06-21 16:03 HeDesongfuqin 阅读(12) 评论(0) 推荐(0)
摘要: import jieba from collections import Counter 读取《红楼梦》文本文件 def read_file(filename): with open(filename, 'r', encoding='utf-8') as f: text = f.read() ret 阅读全文
posted @ 2025-06-21 15:36 HeDesongfuqin 阅读(11) 评论(0) 推荐(0)
摘要: 乒乓竞技分析 import random def printIntro(): print("这个程序模拟两个选手A和B的乒乓球比赛") print("程序运行需要A和B的能力值(以0到1之间的小数表示)") def getInputs(): a = float(input("请输入选手A的能力值(0 阅读全文
posted @ 2025-05-25 11:28 HeDesongfuqin 阅读(70) 评论(0) 推荐(0)
摘要: 源代码改写 import keyword import re import sys def transform_python_file(input_file, output_file): reserved_words = set(keyword.kwlist) with open(input_fil 阅读全文
posted @ 2025-05-18 11:08 HeDesongfuqin 阅读(66) 评论(0) 推荐(0)
摘要: import turtle import time 初始化画笔设置 def setup_pen(): pen = turtle.Turtle() pen.hideturtle() pen.speed(0) pen.pensize(5) return pen 绘制七段数码管的单个段 def draw_ 阅读全文
posted @ 2025-05-05 19:03 HeDesongfuqin 阅读(77) 评论(0) 推荐(0)