当前位置:网站首页>飞桨paddle技术点整理
飞桨paddle技术点整理
2022-08-02 06:38:00 【算法之名】
前面的步骤跟乌班图安装Pytorch、Tensorflow Cuda环境 是一样。
安装GPU版本的paddle
python -m pip install paddlepaddle-gpu==2.3.1.post116 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html张量
import paddleif __name__ == '__main__': a = paddle.to_tensor([[1, 2], [3, 4]]) print(a) print(a.shape) print(a.type) b = paddle.ones([2, 2]) print(b) print(b.type) c = paddle.zeros([2, 2]) print(c) print(c.type) d = paddle.eye(2, 2) print(d) print(d.type) e = paddle.zeros_like(a) print(e) print(e.type) f = paddle.ones_like(a) print(f) print(f.type) g = paddle.arange(0, 11, 1) print(g) print(g.type) h = paddle.linspace(2, 10, 4) print(h) i = paddle.rand([2, 2]) print(i) j = paddle.normal(mean=0.0, std=paddle.rand([5])) print(j) k = paddle.uniform(shape=[2, 2]) print(k) l = paddle.randperm(10) print(l)运行结果
Tensor(shape=[2, 2], dtype=int64, place=Place(gpu:0), stop_gradient=True, [[1, 2], [3, 4]])[2, 2]VarType.LOD_TENSORTensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[1., 1.], [1., 1.]])VarType.LOD_TENSORTensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[0., 0.], [0., 0.]])VarType.LOD_TENSORTensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[1., 0.], [0., 1.]])VarType.LOD_TENSORTensor(shape=[2, 2], dtype=int64, place=Place(gpu:0), stop_gradient=True, [[0, 0], [0, 0]])VarType.LOD_TENSORTensor(shape=[2, 2], dtype=int64, place=Place(gpu:0), stop_gradient=True, [[1, 1], [1, 1]])VarType.LOD_TENSORTensor(shape=[11], dtype=int64, place=Place(gpu:0), stop_gradient=True, [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10])VarType.LOD_TENSORTensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True, [2. , 4.66666651, 7.33333349, 10. ])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[0.17855753, 0.15026711], [0.54343289, 0.04870688]])Tensor(shape=[5], dtype=float32, place=Place(gpu:0), stop_gradient=True, [-0.07493367, -0.10425358, -1.67506480, 0.02299307, 0.38065284])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[ 0.01213348, -0.30467188], [-0.81535292, 0.09958601]])Tensor(shape=[10], dtype=int64, place=Place(gpu:0), stop_gradient=True, [2, 9, 4, 5, 8, 7, 0, 1, 6, 3])- 算数运算、矩阵乘法
import paddleif __name__ == '__main__': a = paddle.to_tensor([[1., 2.], [3., 4.]]) print(a) b = paddle.ones([2, 2]) print(b) c = a + b print(c) c = paddle.add(a, b) print(c) d = paddle.subtract(a, b) print(d) e = paddle.to_tensor([2., 3.]) f = a * e print(f) f = paddle.multiply(a, e) print(f) g = a / e print(g) g = paddle.divide(a, e) print(g) h = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], dtype='float32') i = paddle.to_tensor([[2, 4], [11, 13], [7, 9]], dtype='float32') j = paddle.mm(h, i) print(j) k = paddle.matmul(h, i) print(k)运行结果
Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[1., 2.], [3., 4.]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[1., 1.], [1., 1.]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[2., 3.], [4., 5.]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[2., 3.], [4., 5.]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[0., 1.], [2., 3.]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[2. , 6. ], [6. , 12.]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[2. , 6. ], [6. , 12.]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[0.50000000, 0.66666669], [1.50000000, 1.33333337]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[0.50000000, 0.66666669], [1.50000000, 1.33333337]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[45. , 57. ], [105., 135.]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[45. , 57. ], [105., 135.]])- 平方、开方、对数运算
import paddleif __name__ == '__main__': a = paddle.to_tensor([1, 2, 3]) c = paddle.pow(a, 2) print(c) c = a**2 print(c) a = paddle.to_tensor([2.]) c = paddle.exp(a) print(c) a = paddle.to_tensor([1, 2, 3], dtype='float32') c = paddle.sqrt(a) print(c) c = paddle.log2(a) print(c) c = paddle.log10(a) print(c) c = paddle.log(a) print(c)运行结果
Tensor(shape=[3], dtype=int64, place=Place(gpu:0), stop_gradient=True, [1, 4, 9])Tensor(shape=[3], dtype=int64, place=Place(gpu:0), stop_gradient=True, [1, 4, 9])Tensor(shape=[1], dtype=float32, place=Place(gpu:0), stop_gradient=True, [7.38905621])Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True, [1. , 1.41421354, 1.73205078])Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True, [0. , 1. , 1.58496249])Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True, [0. , 0.30103001, 0.47712126])Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True, [0. , 0.69314718, 1.09861231])- 取整/取余
import paddleif __name__ == '__main__': a = paddle.rand([2, 2]) b = paddle.multiply(a, paddle.to_tensor([10.])) print(b) print(paddle.floor(b)) print(paddle.ceil(b)) print(paddle.round(b)) print(paddle.trunc(b)) print(b % 2)运行结果
Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[2.33501291, 3.41357899], [6.85909081, 5.18760014]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[2., 3.], [6., 5.]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[3., 4.], [7., 6.]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[2., 3.], [7., 5.]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[2., 3.], [6., 5.]])Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True, [[0.33501291, 1.41357899], [0.85909081, 1.18760014]])
边栏推荐
- Project development specification
- 新产品立大功 伟世通第二季度营收双增
- Detailed explanation of 9 common reasons for MySQL index failure
- 【图像去噪】基于matlab双立方插值和稀疏表示图像去噪【含Matlab源码 2009期】
- typescript 'props' is declared but its value is never read solution
- PHP Warning: putenv() has been disabled for security reasons in phar
- request.getSession(), the story
- 享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世
- aTrust项目的相关操作与分享
- 实例028:递归求等差数列
猜你喜欢

See the picture to understand | How to choose sales indicators to measure the health of business growth

【故障诊断分析】基于matlab FFT轴承故障诊断(包络谱)【含Matlab源码 2002期】

Unity Shader学习(七)纹理图像的简单使用

MySQL Advanced Statements (1)
![[数据集][VOC]男女数据集voc格式6188张](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[数据集][VOC]男女数据集voc格式6188张

_2_顺序表

About the local server problem after ue4.27 pixel streaming package

ASP.NET Core Web API 幂等性

【请教】SQL语句按列1去重来计算列2之和

实例029:反向输出
随机推荐
Neo4j 中文开发者月刊 - 202207期
海缆探测仪TSS350(二)
入门opencv,欢笑快乐每一天
Specified URL is not reachable,caused by :‘Read timed out
.NET静态代码织入——肉夹馍(Rougamo) 发布1.1.0
See the picture to understand | How to choose sales indicators to measure the health of business growth
request.getSession(),的故事
PMP新考纲考试内容介绍
雷达人体存在感应器方案,智能物联网感知技术,实时感应人体存在
获取间隔的日期列表工具类
Project development specification
Servlet
php删除一维数组中一个值
实验7 MPLS实验
(Part of it is not understood, and the notes are not completed) [Graph Theory] Difference Constraints
JS初识高阶函数和函数柯里化
Ue after video tutorial first
(笔记整理未完成)【图论】图的遍历
SphereEx苗立尧:云原生架构下的Database Mesh研发实践
optional