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

深入浅出PaddlePaddle函数——paddle.zeros

分类目录:《深入浅出PaddlePaddle函数》总目录
相关文章:
· 深入浅出PaddlePaddle函数——paddle.Tensor
· 深入浅出PaddlePaddle函数——paddle.ones
· 深入浅出PaddlePaddle函数——paddle.zeros
· 深入浅出PaddlePaddle函数——paddle.full
· 深入浅出PaddlePaddle函数——paddle.ones_like
· 深入浅出PaddlePaddle函数——paddle.zeros_like
· 深入浅出PaddlePaddle函数——paddle.full_like


创建一个形状为shape、数据类型为dtype且值全为0的Tensor。

语法

paddle.zeros(shape, dtype=None, name=None)

参数

  • shape:[tuple/list/Tensor] 要创建的Tensor的形状,shape的数据类型为int32int64
  • dtype:[可选,np.dtype/str] 要创建的Tensor的数据类型,可以为boolfloat16float32float64int32int64。如果dtypeNone,那么数据类型为float32
  • name:[可选,str] 具体用法请参见Name,一般无需设置,默认值为None

返回值

Tensor,每个元素都是0,形状为 shape,数据类型为dtype

实例

import paddledata = paddle.zeros(shape=[3, 2], dtype='float32')
# [[0. 0.]
#  [0. 0.]
#  [0. 0.]]
data = paddle.zeros(shape=[2, 2])
# [[0. 0.]
#  [0. 0.]]# shape is a Tensor
shape = paddle.full(shape=[2], dtype='int32', fill_value=2)
data3 = paddle.zeros(shape=shape, dtype='int32')
# [[0 0]
#  [0 0]]

函数实现

def zeros(shape, dtype=None, name=None):"""Creates a tensor of specified :attr:`shape` and :attr:`dtype`, and fills it with 0.Args:shape(tuple|list|Tensor): Shape of the Tensor to be created, the data type of ``shape`` is int32 or int64.dtype(np.dtype|str, optional): Data type of output Tensor, it supportsbool, float16, float32, float64, int32 and int64. Default: if None, the date type is float32.name(str, optional): The default value is None.  Normally there is no need for user to set thisproperty.  For more information, please refer to :ref:`api_guide_Name`.Returns:Tensor: A tensor of data type :attr:`dtype` with shape :attr:`shape` and all elements set to 0.Examples:.. code-block:: pythonimport paddledata = paddle.zeros(shape=[3, 2], dtype='float32')# [[0. 0.]#  [0. 0.]#  [0. 0.]]data = paddle.zeros(shape=[2, 2])# [[0. 0.]#  [0. 0.]]# shape is a Tensorshape = paddle.full(shape=[2], dtype='int32', fill_value=2)data3 = paddle.zeros(shape=shape, dtype='int32')# [[0 0]#  [0 0]]"""if dtype is None:dtype = 'float32'return fill_constant(value=0.0, shape=shape, dtype=dtype, name=name)
http://www.lryc.cn/news/34792.html

相关文章:

  • [力扣sql]
  • Docker基本操作
  • golang如何使用rocketmq 附加闭坑指南 建议收藏!!!
  • C++实现的二叉树创建和遍历,超入门邻家小女也懂了
  • 如何写出高质量的业务接口
  • 3.8多线程
  • 图文讲解MongoDB该怎么安装
  • 「ML 实践篇」机器学习项目落地
  • c++面试技巧-基础篇3
  • MySQL OCP888题解044-从服务器上导入mysql模式数据后的权限问题
  • 实战小项目之视频监控(1-2)
  • 人工智能基础--AI作业1-ML基础
  • 关于JS中this对象指向问题总结
  • Codeforces Round 855 (Div. 3) A-E2
  • Spark Yarn 运行环境搭建
  • SpringMVC 页面跳转指南:转发和重定向的实现与比较
  • ModStartCMS v5.9.0 后台浅色模式,系统样式升级
  • 2020蓝桥杯真题反倍数 C语言/C++
  • PTA:L1-025 正整数A+B、L1-026 I Love GPLT、L1-027 出租(C++)
  • 状态机的Go语言实现版本
  • 第2章 线程安全与共享资源竞争
  • 77. writerows写入多行
  • STM32MP157-Linux输入设备应用编程-多点触摸屏编程
  • mybatis-plus的一般实现过程(超详细)
  • Spark(5):RDD概述
  • 面向对象 - 继承
  • 计算机网络的166个概念你知道几个 第十二部分
  • 【RabbitMQ】RabbitMQ各版本的兼容性与技术支持时限
  • 【Git】P5 Git 远程仓库(3)pull 发生冲突
  • 关于世界坐标系,相机坐标系,图像坐标系,像素坐标系的一些理解