深入浅出PaddlePaddle函数——paddle.zeros
创始人
2024-05-30 22:25:52
0

分类目录:《深入浅出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)

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...