Pytorch学习笔记【6】---基本运算

龙良曲pytorch基础课程学习笔记 什么是Pytorch? PyTorch 是一个基于 Python 的科学计算包,主要定位两类人群: NumPy 的替代品,可以利用 GPU 的性能进行计算 深度学习研究平台拥有足够的灵活性和速度 开始学习 tensor对象 在 TensorFlow 中,数据不是以整数,浮点数或者字符串形式存在的,而是被封装在一个叫做 tensor 的对象中。Tensor是张量的意思,张量包含了0到任意维度的量... 阅读详情

Pytorch学习笔记【6】—基本运算

Pytorch笔记目录:点击进入

1. Add

tensor相加有两种方法效果基本一样

# Add
a = torch.rand(3,4)
b = torch.rand(4)
print(a+b)
# or the result is same
print(torch.add(a,b))
out:
tensor([[0.8559, 1.4637, 1.3004, 0.7409],
        [0.7110, 1.4589, 1.3426, 0.5950],
        [1.0352, 1.1449, 1.6043, 1.5138]])

tensor([[0.8559, 1.4637, 1.3004, 0.7409],
        [0.7110, 1.4589, 1.3426, 0.5950],
        [1.0352, 1.1449, 1.6043, 1.5138]])

2. Sub

# Sub
print(a-b)
print(torch.sub(a,b))
# 比较两种两种运算方法
print(torch.all(torch.eq(a-b,torch.sub(a,b))))
out:
tensor([[ 0.1167, -0.0386, -0.4151, -0.3182],
        [-0.0282, -0.0434, -0.3730, -0.4641],
        [ 0.2959, -0.3574, -0.1112,  0.4546]])
tensor([[ 0.1167, -0.0386, -0.4151, -0.3182],
        [-0.0282, -0.0434, -0.3730, -0.4641],
        [ 0.2959, -0.3574, -0.1112,  0.4546]])
tensor(True)

3. mul and div

# mul
print(torch.all(torch.eq(a*b,torch.mul(a,b))))
# div
print(torch.all(torch.eq(a/b,torch.div(a,b))))
out:
tensor(True)
tensor(True)

4. matmul

# matmul
a = torch.full([2,2],3)
b = torch.ones(2,2)
print(torch.mm(a,b))
print(torch.matmul(a,b))
print(a@b)
out:
tensor([[6., 6.],
        [6., 6.]])
tensor([[6., 6.],
        [6., 6.]])
tensor([[6., 6.],
        [6., 6.]])

5. pow and sqrt

print(a)
print(a.pow(2))
print(a**2)
aa = a**2
print(aa.sqrt())
out:
tensor([[3., 3.],
        [3., 3.]])
tensor([[9., 9.],
        [9., 9.]])

6. Exp and log

# Exp and log
a = torch.exp(torch.ones(2,2))
print(a)
print(torch.log(a))
out:
tensor([[2.7183, 2.7183],
        [2.7183, 2.7183]])
tensor([[1., 1.],
        [1., 1.]])

7. Approximation

# Approximation
a = torch.tensor(3.14)
print(a.floor(),a.ceil(),a.trunc(),a.frac())
out:
tensor(3.) tensor(4.) tensor(3.) tensor(0.1400)

8. round

a = torch.tensor(3.499)
print(a.round())
a = torch.tensor(3.5)
print(a.round())
out:
tensor(3.)
tensor(4.)

9. clamp

把不在范围内的都剪掉

# clamp
grad = torch.rand(2,3)*15
# print max
print(grad.max())
# print min
print(grad.median())
# 把tensor中小于10的数全部变成10
print(grad.clamp(10))
# 把不在这个范围的数字大的变成10,小的变成2
print(grad.clamp(2,10))
out:
tensor(10.0630)
tensor(3.4961)
tensor([[10.0630, 10.0000, 10.0000],
        [10.0000, 10.0000, 10.0000]])
tensor([[10.0000,  3.4961,  2.0000],
        [ 2.0000,  5.1788,  8.3820]])
pyTorch中tensor运算 文章目录PyTorch的简介PyTorch中主要的包PyTorch的安装使用GPU的原因使数据在GPU上运行什么使Tensor(张量)一些术语介绍Tensor的属性介绍(Rank,axis,shape)RankAxis(轴)shape(形状)不同环境下对Tensor的解释卷积神经网络中对Tensor的解释(CNN)PyTorch下的基本张量输出通道和特征映射PyTorch中对Tensor的解释 PyTorch的简介 PyTorch中主要的包 torch:是顶级PyTorch软件包和tensor库。 torc 阅读详情

相关推荐

PyTorch学习笔记(一)Tensor运算

PyToch学习笔记,记录了张量的运算和求梯度的方法。

longrootchen的博客 2311

PyTorch: clamp函数与梯度的关系

在深度学习计算损失函数的过程中,会有这样一个问题,如果Label是1.0,而预测结果是0.0,则BCE损失中理论上计算出的结果是无穷大的(当然pytorch并不会报错,而是将损失上限设在了100.0),在实际开发过程中,我们一般会使用torch.clamp等函数将预测tensor不符合取值范围的值全部置为最小或最大值。那对于这些被替换后的元素,他们会在反向传播过程中对网络产生梯度吗?第一想法是没有,因为这些替换后的新值的来源是一个赋值操作,而非通过网络计算出来的,但为了更好的理解,我们来做一个测试。

龙雪的博客 3246

不用Root也能抓包?Android高版本HTTPS抓包的3种替代方案(含Charles技巧)

本文针对Android高版本HTTPS抓包难题,提供了三种无需Root权限的实战解决方案:利用VirtualXposed等虚拟沙盒环境、配置Postern等系统级代理工具,以及通过修改应用源码或网络安全配置。文章还详细解析了Charles抓包工具在非Root环境下的高级配置与排错技巧,帮助开发者在遵守安全规范的前提下,有效进行网络调试与监控。

http9protocoller的博客 648

Pytorch快速入门一-Tensor

Tensor Variable Tensor Tensor 可以简单地认为是一个数组,且支持高效的科学计算。 基础操作: 从接口的角度讲,对tensor可以分为两类: torch.function,如torch.add(a,b) tensor.function,如a.add(b) 这两种功能是等价的。 从存储角度讲,可以分为以下两类: 不会修改自身的数据,如...

qq_34535410的博客 1万+

Mac上安装Label Studio

以上步骤详细说明了如何在Mac上通过Anaconda安装Label Studio。记得根据你的具体需求选择是否创建新的环境,并使用conda或pip进行安装。安装完成后,务必验证Label Studio是否成功运行。

g2526的博客 1959

Spring AI Alibaba实战训练营-16 NL2SQL (自然语言转 SQL)应用开发指南

本文介绍了一个基于AI的智能BI应用开发项目,主要实现自然语言转SQL(NL2SQL)功能,包含对话模块、MCP模块、向量数据管理模块。项目采用Spring AI Alibaba框架,集成通义千问大模型,支持内存向量库和AnalyticDB向量数据库两种存储方案。重点展示了chat模块的三个控制器实现:AnalyticNl2SqlController用于生产环境,SimpleChatController适用于开发测试,Nl2sqlForGraphController支持基于图的复杂对话流程。系统通过将业务知

program哲学 1589

pytorch 基本数学运算

pytorch中的运算遵循其Broadcasting规则,这里不详细解释。 目录 1. 矩阵对应位置加减乘除 2. 矩阵相乘 3. 幂运算 3. 指数与对数运算 4. 近似取值(向上取整,向下取整,四舍五入,取小数等) 5. clamp 1. 矩阵对应位置加减乘除 包括add(加),sub(减),mul(乘),div(除),pytorch中重载了加减乘除的运算符...

Defiler_Lee的博客 3258

JAVA:Spring Boot 集成 Forest 优雅的 HTTP 客户端

Forest是一个优雅的Java HTTP客户端框架,通过注解式声明简化HTTP接口调用。它支持多HTTP客户端、自动参数绑定、序列化、重试机制和拦截器等功能。本文演示了如何在Spring Boot中集成Forest,包括配置、接口定义和调用示例,还展示了POST请求、文件上传等常见场景。相比传统HTTP客户端,Forest具有声明简洁、功能完善的特点,特别适合微服务调用和第三方API对接,能显著提升开发效率和代码可维护性。

木头 429

pytorch之clamp()函数

https://blog.youkuaiyun.com/u013230189/article/details/82627375

weixin_38698410的博客 1万+

python 实现一个完整的基于Python的多视角三维重建系统,包含特征提取与匹配、相机位姿估计、三维重建、优化和可视化等功能

本文介绍了一个基于Python的多视角三维重建系统的实现,涵盖了特征提取与匹配、相机位姿估计、三维重建、优化和可视化等功能。首先,系统通过安装必要的库(如OpenCV、NumPy等)并加载图像数据,初始化相机参数。接着,系统使用SIFT、SURF或ORB算法提取图像特征点,并通过FLANN或BF方法进行特征匹配,应用Lowe's ratio test筛选优质匹配。该系统为后续的相机位姿估计和三维重建奠定了基础,能够从多视角图像中恢复三维场景结构。

huanghm88的专栏 618

面向元数据的 SAP UI 中枢:namespace sap.ui.mdc 全景解析

如果把应用前端比作一条数据到交互的装配线,sap.ui.mdc 就是那条线的标准化工装:以 PropertyInfo 描述原料,以 Delegate 定义装配方法,以 p13n 与 VariantManagement 交付面向个体的最终产物;而 Condition Model、Operator 与 ValueHelp 则让输入与筛选的语义落地。与 OData V4 服务与 Fiori Elements 宏构件组合使用时,它能在保持一致体验的同时,给自由式开发者留下足够的可编排空间。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 238

pytorch基本操作

1.索引与切片 a = torch.rand(4, 3, 2, 2) print(a.shape, a[0].shape, a[0, 0].shape, a[0, 0, 0].shape, a[0, 2, 1, 0]) print(a[:2].shape, a[:2, :1].shape, a[:2, :1, :1].shape) print(a.index_select(0, torch.tensor([0, 1, 2])).shape ) # 选择第一个维度的下标为0、1和2。第二个参数

scarlet witcher的博客 1183

【人工智能】广度优先搜索(BFS)在人工智能中的应用(Python源码)

本文系统阐述了广度优先搜索(BFS)算法在人工智能领域的核心原理与应用。作为无信息搜索算法,BFS通过FIFO队列实现节点遍历,保证在无权图中的最优性。文章详细解析了BFS的伪代码实现和Python编程示例,并通过机器人路径规划案例展示了其实际应用场景。测试结果表明,BFS能有效解决包含障碍物的网格寻路问题,验证了算法在AI领域的实用价值。该研究为理解基础搜索算法及其工程应用提供了重要参考。

梦想起飞的地方 1143

学习笔记(6):PyTorch从入门到实战一次学会-基本运算操作-上

【超实用课程内容】 本课程从pytorch安装开始讲起,从基本计算结构到深度学习各大神经网络,全程案例代码实战,一步步带大家入门如何使用深度学习框架pytorch,玩转pytorch模型训练等所有知识点。最后通过 kaggle 项目:猫狗分类,实战pytorch深度学习工具。 【课程如何观看?】 PC端:https://edu.csd...

crazystone_nudt的博客 106

【WRF-Urban】使用 NUDAPT 数据集与 BEP/BEP_BEM 方案的 WRF 配置指南

【WRF-Urban】使用 NUDAPT 数据集与 BEP/BEP_BEM 方案的 WRF 配置指南

WW、forever的博客 1964

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Pytorch Tensor基本数学运算

1. 加法运算 示例代码: import torch # 这两个Tensor加减乘除会对b自动进行Broadcasting a = torch.rand(3, 4) b = torch.rand(4) c1 = a + b c2 = torch.add(a, b) print(c1.shape, c2.shape) print(torch.all(torch.eq(c1, c2))) ...

洪流之源 5万+

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

pytorch基本运算-范数

本文介绍了PyTorch中L1和L2范数的计算方法。L2范数计算向量元素平方和的平方根,而L1范数则是向量元素绝对值的总和。文章通过代码示例展示了如何用torch.norm()计算L2范数,用torch.abs().sum()计算L1范数,并扩展到矩阵范数计算。在5×5全1矩阵的案例中验证了计算结果,其中L2范数的平方等于矩阵所有元素平方和,L1范数等于所有元素绝对值之和。这些范数计算在深度学习中具有重要意义。

专注python+工程实践的热心婶子 1328

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

pytorch学习笔记5--pytorch基本运算

文章目录基本运算add/minus/multiply/dividematmul基本函数统计属性normmean,sum,min,max,prod,argmin,argmaxkthvalue,topk\>,>=,<,<=,!=,==高阶操作(GPU)whereGather梯度lossMean Squared Error(MSE):自动求导:torch.autograd.gra...

code_fighter 博客 6726

深度学习|pytorch基本运算

本文介绍了PyTorch的基本运算操作,包括随机张量生成(torch.randn)、多维张量创建(torch.tensor)、张量变形(reshape)、加减运算以及广播机制。文章着重说明各函数的常用参数和使用方法,并通过具体代码示例演示运算效果。作为PyTorch入门指南,本文旨在帮助初学者快速掌握张量基础操作,同时推荐读者参考官方文档深入学习。所有示例代码均附有运行结果截图,直观展示不同运算的实际效果。

专注python+工程实践的热心婶子 1040

pytorch学习笔记(四)--tensor的基本运算

加减乘除 矩阵相乘 torch.mm 只适用于2d,不推荐 torch.matmul 推荐使用 @ 运算符重载 次方运算 a = torch.full([2,2],3) aa = a.pow(2) 操作运算如下: a.pow(n) 表示an a**n 表示an aa.sqrt() 表示aa 1/2 aa.rsqrt() 表示aa1/3 注意这里没有torch. 幂/对数 a = to...

ThetaQing的博客 7537

pytorch入门--矩阵基本运算

本篇pytorch的矩阵基本运算进行展示,包含: add/subtract/multiply/divide matmul pow 次方 sqrt/rsqrt 次方根 近似运算 上下界操作 使用方法和含义均在代码的批注中给出,因为有较多的输出,所以设置输出内容的第一个值为当前print()方法所在的行 矩阵基本运算 import torch import numpy as np import sys loc = sys._getframe() _ = '\n' ''' add/subtract/m

qq_43923588的博客 4536

pytorch 基本运算

有重载运算符 和 函数两种方法进行张量的运算 import torch import numpy as np a = torch.rand(2,3) b = torch.rand(3) # 这里b 使用了 broatcasting 自动进行了维度扩展 print("运算符 + 与 add() 方法运算结果一致:{} ".format(torch.all(torch.eq(torch.add(a,b...

qq_37333800的博客 847

Pytorch学习(3):Tensor合并、分割与基本运算

文章目录前言一、合并Cat/Stack1.Cat2.Stack二、分割Split/Chunk1.Split2.Chunk三、基本运算1.加减乘除2.矩阵乘法mm/@/matmul3.幂运算**4.指数exp/对数log5.近似floor/ceil/round/trunc/frac6.裁剪(归化)clamp总结 前言 Pytorch学习笔记第三篇,关于Tensor的合并(cat/stack)、分割(split/chunk)与基本运算。 一、合并Cat/Stack 1.Cat Tensor中cat是co..

Leafing_的博客 6214

PyTorch张量运算

本文介绍PyTorch张量运算

诸神缄默不语的博客 1803

【Pytorch基础】Pytorch的基本运算操作

  Pytorch跟Python一样都是一种编程语言,只不过Pytorch可以在GPU中进行计算。简单理解的话,就是这个区别吧。至于如何学习Pytorch,个人 觉得完全可以类比,Python两者语法跟用法没有太大差异。再者,为什么学习Pytorch基本计算,而不是用Python基本计算代替再转成tensor格式。个人在代码实现中的体会是:太麻烦,因为Pytorch默认创建变量的类型是float32,使用Python的数据类型如array是float64,如果进行tensor的转换后在计算会报错,变量类型不

sxl的博客 2080

PyTorch基本数学运算

矩阵的加减乘(数乘)除(数除) 可以使用符号+ - * / a+b a-b a*b a/b 也可以写add sub mul div torch.add(a,b) torch.sub(a,b) torch.mul(a,b) torch.div(a,b) //表示整除 这样的运算是允许的,它会进行维度扩展 矩阵的乘与除 torch.matmul或者使用@ mm不推荐,因为它只能处理2*2的 对于高维矩阵,@与matmul会计算最后两维的乘法,前面的不进行改变。如果前面的值不对应会使用brodcasting进

Temmie1024的博客 1384
上一篇: Pytorch学习笔记【5】---tensor的拼接和拆分
下一篇: Pytorch学习笔记【7】---统计属性
AndSonder
博客等级 码龄7年 364粉丝 154原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值