元组和记录
lax_coordinates = (33.9425, -118.408056) # 洛杉矶国际机场的经纬度 city, year, pop, chg, area = ('Tokyo', 2003, 32450, 0.66, 8014) # 东京市的一些信息:市名
lax_coordinates = (33.9425, -118.408056) # 洛杉矶国际机场的经纬度 city, year, pop, chg, area = ('Tokyo', 2003, 32450, 0.66, 8014) # 东京市的一些信息:市名
symbols = '%^&*♕' codes = [] # 创建一个codes列表 for symbol in symbols: # 用for循环迭代symbols codes.append(ord(symbol)) # 将symbols中的元素迭代取出
PyTorch的配置 这里附上官网的链接https://pytorch.org/get-started/locally/ CPU版本 选择PyTorch版本(PyTorch Build),Stable(稳定版),Nightly(测试版) 系统版本,这里只介绍Windows系统的P
import torch from torchvision import transforms from torchvision import datasets from torch.utils.data import DataLoader import torch.nn.fun
import torch # 引入模块PyTorch from torchvision import transforms # 从torch视觉中引入转换函数 from torchvision import datasets # 导入数据库 from torch.utils.da
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
这里选择将模型和loss还有数据都在GPU上,方便后续能够将大型神经网络的计算图放在GPU上来加快训练速度 import torch # 引入PyTorch模块 x = torch.tensor([[1.0], [2.0], [3.0]]).cuda() # 创建张量x,y并使用
利用特殊方法,来使得自定义对象来实现一个二维向量(Vector)类 一个简单的二维向量类 from math import hypot class Vector: def init(self, x=0, y=0): self.x = x # 将输入的x,y分别赋值给类属性
import collections # 引入collections模块 Card = collections.namedtuple('Card', ['rank', 'suit']) # 用namedtuple创造了一个简单的类C
从零开始学Python 第一节课 学会了Python的变量赋值、运算符使用和强制类型转换 if name == 'main': print('Hello World') print('人因梦想而伟大') print(