当前位置: 首页 > news >正文

【Pytorch笔记】3.数学运算

深度之眼官方账号 - 01-03-mp4-张量操作与线性回归

torch.add()

功能:逐元素计算input+alpha×other

torch.add(input,alpha=1,other,out=None)

input:tensor;
alpha:other的系数,是个实数;
other:和input同样形状的tensor。

import torcht1 = torch.tensor([[2, 3], [4, 5]])
t2 = torch.tensor([[1, 1], [2, 2]])
t = torch.add(t1, alpha=2, other=t2)
print(t)

输出:

tensor([[4, 5],[8, 9]])

torch.sub()

功能:逐元素计算input-alpha×other

torch.sub(input,alpha=1,other,out=None)

input:tensor;
alpha:other的系数,是个实数;
other:和input同样形状的tensor。

import torcht1 = torch.tensor([[2, 3], [4, 5]])
t2 = torch.tensor([[1, 1], [2, 2]])
t = torch.add(t1, alpha=2, other=t2)
print(t)

输出:

tensor([[0, 1],[0, 1]])

torch.mul()

功能:逐元素计算 o u t i = i n p u t i × o t h e r i out_i=input_i \times other_i outi=inputi×otheri

torch.mul(input,other)

input:tensor;
other:和input同样尺寸的tensor。
other支持广播,即可以只向other传入一个数,torch利用广播机制变成同样尺寸的tensor。

import torcht1 = torch.tensor([[9, 12], [15, 18]])
t2 = torch.tensor([[3, 3], [2, 2]])
t = torch.mul(t1, other=t2)
print(t)

输出:

tensor([[27, 36],[30, 36]])

torch.div()

功能:逐元素计算 o u t i = i n p u t i o t h e r out_i=\frac{input_i}{other} outi=otherinputi

torch.div(input,other)

input:tensor;
other:和input同样尺寸的、元素不能为0的tensor。
other支持广播,即可以只向other传入一个数,torch利用广播机制变成同样尺寸的tensor。

import torcht1 = torch.tensor([[9, 12], [4, 6]])
t2 = torch.tensor([[3, 3], [2, 2]])
t = torch.div(t1, other=t2)
print(t)

输出:

tensor([[3., 4.],[2., 3.]])

torch.addcmul()

功能:逐元素计算 o u t i = i n p u t i + v a l u e × t e n s o r 1 i × t e n s o r 2 i out_i=input_i+value \times tensor1_i \times tensor2_i outi=inputi+value×tensor1i×tensor2i

torch.addcmul(input,value=1,tensor1,tensor2,out=None)

input:输入的tensor;
value:见公式,实数;
tensor1:和input相同形状的tensor,见公式;
tensor2:和input相同形状的tensor,见公式。

import torcht1 = torch.tensor([[2., 3.], [4., 5.]])
t2 = torch.tensor([[4., 6.], [8., 10.]])
t3 = torch.tensor([[2., 2.], [2., 2.]])
t = torch.addcmul(t1, value=2, tensor1=t2, tensor2=t3)
print(t)

输出:

tensor([[18., 27.],[36., 45.]])

torch.addcdiv()

功能:逐元素计算 o u t i = i n p u t i + v a l u e × t e n s o r 1 i t e n s o r 2 i out_i=input_i+value \times\frac{tensor1_i}{tensor2_i} outi=inputi+value×tensor2itensor1i

torch.addcdiv(input,value=1,tensor1,tensor2,out=None)

input:输入的tensor;
value:见公式,实数;
tensor1:和input相同形状的tensor,见公式;
tensor2:和input相同形状但是元素中不能出现0的tensor,见公式。
注:input、tensor1、tensor2的内容需要是浮点型。如果使用整数会报如下错误:

RuntimeError: Integer division with addcdiv is no longer supported, and in a future release addcdiv will perform a true division of tensor1 and tensor2. The historic addcdiv behavior can be implemented as (input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype) for integer inputs and as (input + value * tensor1 / tensor2) for float inputs. The future addcdiv behavior is just the latter implementation: (input + value * tensor1 / tensor2), for all dtypes.

import torcht1 = torch.tensor([[2., 3.], [4., 5.]])
t2 = torch.tensor([[4., 6.], [8., 10.]])
t3 = torch.tensor([[2., 2.], [2., 2.]])
t = torch.addcdiv(t1, value=2, tensor1=t2, tensor2=t3)
print(t)

输出:

tensor([[ 6.,  9.],[12., 15.]])

torch.log()

功能:逐元素求解 o u t i = l o g e ( i n p u t i ) out_i=log_e(input_i) outi=loge(inputi)

torch.log(input,out=None)

input:待求解的tensor。

import torcht1 = torch.tensor([[9., -12.], [15., 18.]])
t = torch.log(t1)
print(t)

输出:

tensor([[2.1972,    nan],[2.7081, 2.8904]])

torch.log10()

功能:逐元素求解 o u t i = l o g 10 ( i n p u t i ) out_i=log_{10}(input_i) outi=log10(inputi)

torch.log10(input,out=None)

input:待求解的tensor。

import torcht1 = torch.tensor([[9., -12.], [15., 18.]])
t = torch.log10(t1)
print(t)

输出:

tensor([[0.9542,    nan],[1.1761, 1.2553]])

torch.log2()

功能:逐元素求解 o u t i = l o g 2 ( i n p u t i ) out_i=log_2(input_i) outi=log2(inputi)

torch.log2(input,out=None)

input:待求解的tensor。

import torcht1 = torch.tensor([[8., -12.], [16., 18.]])
t = torch.log2(t1)
print(t)

输出:

tensor([[3.0000,    nan],[4.0000, 4.1699]])

torch.exp()

功能:逐元素求解 o u t i = e i n p u t i out_i=e^{input_i} outi=einputi

torch.exp(input,out=None)

input:待求解的tensor。

import math
import torcht1 = torch.tensor([[-2., 0.], [1., math.log(2.)]])
t = torch.exp(t1)
print(t)

输出:

tensor([[0.1353, 1.0000],[2.7183, 2.0000]])

torch.pow()

功能:逐元素求解 o u t i = x i e x p o n e n t i out_i=x_i^{exponent_i} outi=xiexponenti

torch.pow(input,exponent,out=None)

input:待求解的tensor。
exponent:与input相同形状的tensor。
如果exponent是一个数,torch会广播成一个和input相同形状的tensor。

import torcht1 = torch.tensor([[1., 2.], [3., 4.]])
t2 = torch.tensor([[3., 2.], [4., 2.]])
t3 = torch.pow(t1, 2.)
t4 = torch.pow(t1, t2)
print(t3)
print(t4)

输出:

tensor([[ 1.,  4.],[ 9., 16.]])
tensor([[ 1.,  4.],[81., 16.]])

tensor.abs()

功能:逐元素取绝对值, o u t i = ∣ i n p u t i ∣ out_i=|input_i| outi=inputi

torch.abs(input,out=None)

input:待求解的tensor。

import torcht1 = torch.tensor([[1., -2.], [-3., 4.]])
t = torch.abs(t1)
print(t)

输出:

tensor([[1., 2.],[3., 4.]])

tensor.acos()

功能:逐元素求解 o u t i = c o s − 1 ( i n p u t i ) out_i=cos^{-1}(input_i) outi=cos1(inputi)

torch.acos(input,out=None)

input:待求解的tensor。

import torcht1 = torch.randn(4)
print(t1)
t = torch.acos(t1)
print(t)

输出:

tensor([ 0.5100,  0.1678, -0.0250,  0.3119])
tensor([1.0357, 1.4022, 1.5958, 1.2536])

torch.cosh()

功能:逐元素求解 o u t i = c o s h ( i n p u t i ) out_i=cosh(input_i) outi=cosh(inputi)
注: c o s h ( x ) = e x + e − x 2 cosh(x)=\frac{e^x+e^{-x}}{2} cosh(x)=2ex+ex

torch.cosh(input,out=None)

input:待求解的tensor。

import torcht1 = torch.randn(4)
print(t1)
t = torch.cosh(t1)
print(t)torch.cosh(input,out=None)

输出:

tensor([-0.3447, -0.2875, -0.2717, -1.3635])
tensor([1.0600, 1.0416, 1.0371, 2.0828])

torch.cos()

功能:逐元素求解 o u t i = c o s ( i n p u t i ) out_i=cos(input_i) outi=cos(inputi)

torch.cos(input,out=None)

input:待求解的tensor。

import torcht1 = torch.randn(4)
print(t1)
t = torch.cos(t1)
print(t)torch.cosh(input,out=None)

输出:

tensor([-0.6443, -0.8991,  1.2432, -0.3162])
tensor([0.7995, 0.6223, 0.3218, 0.9504])

torch.asin()

功能:逐元素求解 o u t i = s i n − 1 ( i n p u t i ) out_i=sin^{-1}(input_i) outi=sin1(inputi)

torch.asin(input,out=None)

input:待求解的tensor。

import torcht1 = torch.randn(4)
print(t1)
t = torch.asin(t1)
print(t)

输出:

tensor([-0.7372, -0.0238, -1.8213, -0.0912])
tensor([-0.8289, -0.0238,     nan, -0.0913])

torch.atan()

功能:逐元素求解 o u t i = t a n − 1 ( i n p u t i ) out_i=tan^{-1}(input_i) outi=tan1(inputi)

torch.atan(input,out=None)

input:待求解的tensor。

import torcht1 = torch.randn(4)
print(t1)
t = torch.atan(t1)
print(t)

输出:

tensor([ 0.3620, -0.6551,  1.0304,  2.1545])
tensor([ 0.3474, -0.5799,  0.8003,  1.1362])

torch.atan2()

功能:逐元素求解 o u t i = t a n − 1 ( i n p u t i o t h e r i ) out_i=tan^{-1}(\frac{input_i}{other_i}) outi=tan1(otheriinputi)

torch.atan(input,other,out=None)

input:待求解的tensor。

import torcht1 = torch.randn(4)
print(t1)
t2 = torch.randn(4)
print(t2)
t = torch.atan2(t1, t2)
print(t)

输出:

tensor([ 1.9372,  0.7993, -1.4123,  0.4260])
tensor([-1.5106,  1.2147, -1.4479,  0.1674])
tensor([ 2.2331,  0.5820, -2.3686,  1.1963])

相关文章:

【Pytorch笔记】3.数学运算

深度之眼官方账号 - 01-03-mp4-张量操作与线性回归 torch.add() 功能:逐元素计算inputalphaother。 torch.add(input,alpha1,other,outNone)input:tensor; alpha:other的系数,是个实数; other&#xff1…...

MeterSphere 监控方案

前言:在部署MeterSphere之后,很多时候需要看下MeterSphere服务的监控信息,虽然有监控告警脚本,但还不是太直观,所以就结合 PrometheusExporterGrafana 部署一套完整的MeterSphere监控方案。 首先我们先罗列一下需要监控…...

elementui-plus+ts+axios使用el-upload组件自定义上传

1.前言: 使用element ui有很多便捷之处,但是由于是封装的组件和自己写还是有些许的不一样,这里主要解决几个问题。 1. 如何获取子组件实例 2. 如何自定义上传方法 2.两个问题: ⛺️ 获取子组件实例 实际上vue一般通过ref获取子组…...

【STM32单片机】u8g2智能风扇设计

文章目录 一、功能简介二、软件设计三、实验现象联系作者 一、功能简介 本项目使用STM32F103C8T6单片机控制器,使用按键、IIC OLED模块、DS18B20温度传感器、直流电机、红外遥控等。 主要功能: 初始化后进入温度显示界面,系统初始状态为手动…...

Java中的IO流的缓冲流

不爱生姜不吃醋⭐️ 如果本文有什么错误的话欢迎在评论区中指正 与其明天开始,不如现在行动! 文章目录 🌴IO流体系结构🌴缓冲流1.提高效率的原理2.缓冲流的类型3.字符缓冲流两个特有方法 🌴总结 🌴IO流体系…...

7、SpringBoot_高级配置

一、配置高级 1.临时属性设置 1.1引出问题 如果目标电脑上8080端口已经使用,再次使用该端口会出现端口占用问题 解决方式 重新更换配置文件修改端口打包通过临时属性配置新端口更换配置文件 1.2添加临时属性配置 通过临时属性修改8080端口 java -jar 项目.jar…...

cocos2dx查看版本号的方法

打开文件:项目根目录\frameworks\cocos2d-x\docs\RELEASE_NOTES.md 知道引擎版本号的意义: 1.面试中经常被问到(面试官想知道你会不会查版本号,你会查也不一定会去看,如果你去看了说明你是一个有心人,或者想深入研究下…...

某高校的毕设

最近通过某个平台接的单子,最后Kali做的测试没有公开可以私聊给教程。 下面是规划与配置 1.vlan方面:推荐一个vlan下的所有主机为一个子网网段 连接电脑和http客户端的接口配置为access接口 交换机与交换机或路由器连接的接口配置为trunk接口---也可以…...

利用uvicorn、Starlette和pipeline将一个训练好的大模型发布成一个web服务

技术名词: 1、Starlette: 它是一个轻量级、高度可用性和可扩展性的Web框架,它专门为异步应用程序设计。 Starlette基于Python 3.6的异步/协程语法,具有快速响应性能和低延迟。你可以将它理解为Java的Spring。 安装:…...

贝赛尔曲线 - Vue3实现加入购物车抛物线效果组件

贝赛尔曲线 - Vue3实现加入购物车抛物线效果组件(可连续多个动画,动态回收DOM) 前言 在前几天的一次迭代中,我遇到了这么一个需求,模仿支付宝首页应用中心的编辑功能,支持编辑首页展示的应用,…...

AddressSanitizer failed to allocate 0xdfff0001000 (15392894357504) bytes解决方法

打开一个编译选项启用ASan的程序: AddressSanitizer failed to allocate 0xdfff0001000 (15392894357504) bytes然后程序启动失败。 原因: [cfe-dev] Question about Clang/LLVM addresssanitizer /proc/sys/vm/overcommit_memory是一个用于控制内存…...

Fortinet 2023上半年全球威胁态势研究报告:勒索软件检测成下降趋势,针对性攻击持续升温

近日,专注于推动网络与安全融合的全球网络安全领导者Fortinet(NASDAQ:FTNT),发布《2023上半年全球威胁态势研究报告》。报告显示,2023 年上半年勒索软件检出数量继续下降、高级持续性威胁(APT&a…...

MySQL ——多表连接查询

一、(左、右和全)连接概念 内连接: 假设A和B表进行连接,使用内连接的话,凡是A表和B表能够匹配上的记录查询出来。A和B两张表没有主付之分,两张表是平等的。 关键字:inner join on 语句&#xf…...

前沿技术 --> 待定

一、可会可不会 1.1如何优雅的编写技术文档 网址: 如何优雅的编写技术文档? - YouTube...

Linux定时python脚本(crontab版本)

1.0 使用Linux系统命令 crontab 自带的定时命令2.0 crontab的使用 2.1 添加定时任务 crontab -e2.2 查看定时任务的完成情况 2.2.1 查看日志 tail -f /var/log/syslog | grep CRON 2.2.2 任务执行情况 grep CRON /var/log/syslog 2.3 定时任务的规则 每隔一分钟执行一次…...

修改 Ubuntu .cache 和 pip cache 默认路径

修改 Ubuntu .cache 和 pip cache 默认路径 非常不建议修改 .cache 默认路径,除非你知道修改后的影响。 执行下面命令进行修改, vi /root/.bashrc--- 追加 export XDG_CACHE_HOME/u01/.cache export PIP_CACHE_DIR/u01/.cache ---完结!...

【Java SE】Lambda表达式

目录 ♫什么是Lambda表达式 ♫Lambda表达式的语法 ♫函数式接口 ♫Lambda表达式的使用 ♫变量捕获 ♫ Lambda表达式在集合中的使用 ♪Collection的foreach(): ♪List的sort(): ♪Map的foreach() ♫什么是Lambda表达式 Lambda 表达式是 Java SE 8中一个…...

Kafka-UI

有多款kafka管理应用,目前选择的是github上star最多的UI for Apache Kafka。 关于 To run UI for Apache Kafka, you can use either a pre-built Docker image or build it (or a jar file) yourself. UI for Apache Kafka is a versatile, fast, and lightweight…...

Unity 制作登录功能02-创建和链接数据库(SQlite)

国际惯例:先看效果 1.SQlite是一种嵌入型数据库 在Unity开发游戏时使用SQLite有多种原因,以下是其中一些主要原因: 嵌入式数据库:SQLite是一个嵌入式数据库引擎,这意味着它不需要单独的服务器进程。这使得使用SQLite非…...

算法 岛屿数量-(递归回溯)

牛客网 BM57. 二维矩阵,值为1表示岛屿,0表示海洋,求海洋中岛屿数量。 解题思路: 遍历二维数组,值为1增加岛屿数量记数,同时对此位置进行单独递归遍历上下左右4个方向,将数组坐标范围内同时值为1的元素置…...

【Linux】shell脚本忽略错误继续执行

在 shell 脚本中,可以使用 set -e 命令来设置脚本在遇到错误时退出执行。如果你希望脚本忽略错误并继续执行,可以在脚本开头添加 set e 命令来取消该设置。 举例1 #!/bin/bash# 取消 set -e 的设置 set e# 执行命令,并忽略错误 rm somefile…...

React第五十七节 Router中RouterProvider使用详解及注意事项

前言 在 React Router v6.4 中&#xff0c;RouterProvider 是一个核心组件&#xff0c;用于提供基于数据路由&#xff08;data routers&#xff09;的新型路由方案。 它替代了传统的 <BrowserRouter>&#xff0c;支持更强大的数据加载和操作功能&#xff08;如 loader 和…...

【Redis技术进阶之路】「原理分析系列开篇」分析客户端和服务端网络诵信交互实现(服务端执行命令请求的过程 - 初始化服务器)

服务端执行命令请求的过程 【专栏简介】【技术大纲】【专栏目标】【目标人群】1. Redis爱好者与社区成员2. 后端开发和系统架构师3. 计算机专业的本科生及研究生 初始化服务器1. 初始化服务器状态结构初始化RedisServer变量 2. 加载相关系统配置和用户配置参数定制化配置参数案…...

高频面试之3Zookeeper

高频面试之3Zookeeper 文章目录 高频面试之3Zookeeper3.1 常用命令3.2 选举机制3.3 Zookeeper符合法则中哪两个&#xff1f;3.4 Zookeeper脑裂3.5 Zookeeper用来干嘛了 3.1 常用命令 ls、get、create、delete、deleteall3.2 选举机制 半数机制&#xff08;过半机制&#xff0…...

抖音增长新引擎:品融电商,一站式全案代运营领跑者

抖音增长新引擎&#xff1a;品融电商&#xff0c;一站式全案代运营领跑者 在抖音这个日活超7亿的流量汪洋中&#xff0c;品牌如何破浪前行&#xff1f;自建团队成本高、效果难控&#xff1b;碎片化运营又难成合力——这正是许多企业面临的增长困局。品融电商以「抖音全案代运营…...

【单片机期末】单片机系统设计

主要内容&#xff1a;系统状态机&#xff0c;系统时基&#xff0c;系统需求分析&#xff0c;系统构建&#xff0c;系统状态流图 一、题目要求 二、绘制系统状态流图 题目&#xff1a;根据上述描述绘制系统状态流图&#xff0c;注明状态转移条件及方向。 三、利用定时器产生时…...

优选算法第十二讲:队列 + 宽搜 优先级队列

优选算法第十二讲&#xff1a;队列 宽搜 && 优先级队列 1.N叉树的层序遍历2.二叉树的锯齿型层序遍历3.二叉树最大宽度4.在每个树行中找最大值5.优先级队列 -- 最后一块石头的重量6.数据流中的第K大元素7.前K个高频单词8.数据流的中位数 1.N叉树的层序遍历 2.二叉树的锯…...

sipsak:SIP瑞士军刀!全参数详细教程!Kali Linux教程!

简介 sipsak 是一个面向会话初始协议 (SIP) 应用程序开发人员和管理员的小型命令行工具。它可以用于对 SIP 应用程序和设备进行一些简单的测试。 sipsak 是一款 SIP 压力和诊断实用程序。它通过 sip-uri 向服务器发送 SIP 请求&#xff0c;并检查收到的响应。它以以下模式之一…...

JVM 内存结构 详解

内存结构 运行时数据区&#xff1a; Java虚拟机在运行Java程序过程中管理的内存区域。 程序计数器&#xff1a; ​ 线程私有&#xff0c;程序控制流的指示器&#xff0c;分支、循环、跳转、异常处理、线程恢复等基础功能都依赖这个计数器完成。 ​ 每个线程都有一个程序计数…...

第7篇:中间件全链路监控与 SQL 性能分析实践

7.1 章节导读 在构建数据库中间件的过程中&#xff0c;可观测性 和 性能分析 是保障系统稳定性与可维护性的核心能力。 特别是在复杂分布式场景中&#xff0c;必须做到&#xff1a; &#x1f50d; 追踪每一条 SQL 的生命周期&#xff08;从入口到数据库执行&#xff09;&#…...