深入浅出PaddlePaddle函数——paddle.shape
分类目录:《深入浅出PaddlePaddle函数》总目录
语法
paddle.shape(input)
参数
input
:[Tensor
] 输入的多维Tensor
或SelectedRows
,数据类型为float16
、float32
、float64
、int32
、int64
。如果输入是SelectedRows
类型,则返回其内部持有Tensor
的shape
。
返回值
表示输入 ensor
或SelectedRows
的shape
的Tensor
实例
import paddle.fluid as fluid
import numpy as np
import paddle
paddle.enable_static()inputs = fluid.data(name="x", shape=[3, 100, 100], dtype="float32")
output = fluid.layers.shape(inputs)exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())img = np.ones((3, 100, 100)).astype(np.float32)res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output])
print(res) # [array([ 3, 100, 100], dtype=int32)]
函数实现
def shape(input):""":alias_main: paddle.shape:alias: paddle.shape,paddle.tensor.shape,paddle.tensor.attribute.shape:old_api: paddle.fluid.layers.shape**Shape Layer**Get the shape of the input... code-block:: textCase1:Given N-D Tensor:input = [ [1, 2, 3, 4], [5, 6, 7, 8] ]Then:input.shape = [2, 4]Case2:Given SelectedRows:input.rows = [0, 4, 19]input.height = 20input.value = [ [1, 2], [3, 4], [5, 6] ] # inner tensorThen:input.shape = [3, 2]Args:input (Variable): The input can be N-D Tensor or SelectedRows with data type bool, float16, float32, float64, int32, int64.If input variable is type of SelectedRows, returns the shape of it's inner tensor.Returns:Variable (Tensor): The shape of the input variable.Examples:.. code-block:: pythonimport paddle.fluid as fluidimport numpy as npimport paddlepaddle.enable_static()inputs = fluid.data(name="x", shape=[3, 100, 100], dtype="float32")output = fluid.layers.shape(inputs)exe = fluid.Executor(fluid.CPUPlace())exe.run(fluid.default_startup_program())img = np.ones((3, 100, 100)).astype(np.float32)res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output])print(res) # [array([ 3, 100, 100], dtype=int32)]"""if in_dygraph_mode():out = _C_ops.shape(input)out.stop_gradient = Truereturn outif _in_legacy_dygraph():out = _legacy_C_ops.shape(input)out.stop_gradient = Truereturn outcheck_variable_and_dtype(input, 'input', ['bool', 'float16', 'float32', 'float64', 'int32', 'int64', 'complex64','complex128'], 'shape')helper = LayerHelper('shape', **locals())out = helper.create_variable_for_type_inference(dtype='int32')helper.append_op(type='shape',inputs={'Input': input},outputs={'Out': out},stop_gradient=True)return out
深入浅出PaddlePaddle函数——paddle.shape相关推荐
- 深入浅出PaddlePaddle函数——paddle.Tensor
分类目录:<深入浅出PaddlePaddle函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.Tensor · 深入浅出Pytorch函数--torch.Tenso ...
- 深入浅出PaddlePaddle函数——paddle.ones_like
分类目录:<深入浅出PaddlePaddle函数>总目录 相关文章: · 深入浅出PaddlePaddle函数--paddle.Tensor · 深入浅出PaddlePaddle函数--p ...
- 深入浅出PaddlePaddle函数——paddle.arange
分类目录:<深入浅出PaddlePaddle函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.range · 深入浅出Pytorch函数--torch.arange ...
- 深入浅出PaddlePaddle函数——paddle.numel
分类目录:<深入浅出PaddlePaddle函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.size · 深入浅出Pytorch函数--torch.numel · ...
- 深入浅出TensorFlow2函数——tf.constant
分类目录:<深入浅出TensorFlow2函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.constant · 深入浅出TensorFlow2函数--tf.Ten ...
- 深入浅出Pytorch函数——torch.arange
分类目录:<深入浅出Pytorch函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.range · 深入浅出Pytorch函数--torch.arange · 深入 ...
- 深入浅出Pytorch函数——torch.exp
分类目录:<深入浅出Pytorch函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.exp · 深入浅出TensorFlow2函数--tf.math.exp · 深 ...
- 深入浅出Pytorch函数——torch.numel
分类目录:<深入浅出Pytorch函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.size · 深入浅出Pytorch函数--torch.numel · 深入浅出 ...
- 深入浅出TensorFlow2函数——tf.data.Dataset.batch
分类目录:<深入浅出TensorFlow2函数>总目录 语法 batch(batch_size, drop_remainder=False, num_parallel_calls=None ...
最新文章
- 06.系统编程-3.进程VS线程比较
- Redis分布式锁(ServiceStack.Redis实现)
- 如何在Java中生成比特币钱包地址
- 常用c语言函数实现,常用的C语言库函数实现
- PHP 通用检测函数集
- 图片处理应用:固定容器缩略图实现
- MySQL-快速入门(13)MySQL日志
- windows下WDK创建免费的测试证书,并签名windows驱动文件(附带测试效果)
- 台式机与笔记本辐射谁大
- proc 文件的创建和读写
- xposed模块编写教程_新手不要再被误导!这是一篇最新的Xposed模块编写教程
- 想要分离歌曲内的伴奏?轻松搞定
- 垃圾收集器回收种类 以及七种垃圾收集器
- python画图:小圆覆盖大圆问题
- Python爬取房价
- 转载:一篇文章看明白 Android 系统启动时都干了什么
- 酷!我把废旧的Android手机改造成了Linux服务器
- 【转】win10录屏快捷键报错显示需要新应用打开ms-gamingoverlay
- 股票数据API接口合集:腾讯股票接口、麦蕊智数股票接口、和讯网股票接口、新浪股票接口、雪球股票数据、网易股票数据
- linux 820m驱动下载,下载:NVIDIA显卡最新177.67版驱动For Linux