元组和记录

lax_coordinates = (33.9425, -118.408056) # 洛杉矶国际机场的经纬度 city, year, pop, chg, area = ('Tokyo', 2003, 32450, 0.66, 8014) # 东京市的一些信息:市名

2021-09-08 · 2 分钟 · 223 字 · 里列昂

Python列表推导和可读性

symbols = '%^&*♕' codes = [] # 创建一个codes列表 for symbol in symbols: # 用for循环迭代symbols codes.append(ord(symbol)) # 将symbols中的元素迭代取出

2021-09-08 · 1 分钟 · 80 字 · 里列昂

PyTorch环境的配置

PyTorch的配置 这里附上官网的链接https://pytorch.org/get-started/locally/ CPU版本 选择PyTorch版本(PyTorch Build),Stable(稳定版),Nightly(测试版) 系统版本,这里只介绍Windows系统的P

2021-09-06 · 1 分钟 · 28 字 · 里列昂

MNIST手写数字集的多分类问题(Convolution Neural Network)

import torch from torchvision import transforms from torchvision import datasets from torch.utils.data import DataLoader import torch.nn.fun

2021-09-06 · 2 分钟 · 371 字 · 里列昂

MNIST手写数字集的多分类问题(Linear Layer)

import torch # 引入模块PyTorch from torchvision import transforms # 从torch视觉中引入转换函数 from torchvision import datasets # 导入数据库 from torch.utils.da

2021-09-06 · 2 分钟 · 406 字 · 里列昂

PyTorch创建简单的逻辑回归模型(LogisticRegression)

import torch import torch.nn.functional as F # 从torch引入激活函数 x_data = torch.tensor([[1.0], [2.0], [3.0]]).cuda() # 将数据放在GPU上 y_data = torch.t

2021-09-06 · 1 分钟 · 128 字 · 里列昂

PyTorch实现LinearModel

这里选择将模型和loss还有数据都在GPU上,方便后续能够将大型神经网络的计算图放在GPU上来加快训练速度 import torch # 引入PyTorch模块 x = torch.tensor([[1.0], [2.0], [3.0]]).cuda() # 创建张量x,y并使用

2021-09-06 · 1 分钟 · 146 字 · 里列昂

Python模拟数据类型

利用特殊方法,来使得自定义对象来实现一个二维向量(Vector)类 一个简单的二维向量类 from math import hypot class Vector: def init(self, x=0, y=0): self.x = x # 将输入的x,y分别赋值给类属性

2021-09-06 · 1 分钟 · 139 字 · 里列昂

一摞Python风格纸牌

import collections # 引入collections模块 Card = collections.namedtuple('Card', ['rank', 'suit']) # 用namedtuple创造了一个简单的类C

2021-09-05 · 2 分钟 · 321 字 · 里列昂

Python语言基础学习报告

从零开始学Python 第一节课 学会了Python的变量赋值、运算符使用和强制类型转换 if name == 'main': print('Hello World') print('人因梦想而伟大') print(

2021-09-04 · 1 分钟 · 69 字 · 里列昂