分类目录:《深入浅出PaddlePaddle函数》总目录


语法

paddle.shape(input)

参数

  • input:[Tensor] 输入的多维TensorSelectedRows,数据类型为float16float32float64int32int64。如果输入是SelectedRows类型,则返回其内部持有Tensorshape

返回值

表示输入 ensorSelectedRowsshapeTensor

实例

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相关推荐

  1. 深入浅出PaddlePaddle函数——paddle.Tensor

    分类目录:<深入浅出PaddlePaddle函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.Tensor · 深入浅出Pytorch函数--torch.Tenso ...

  2. 深入浅出PaddlePaddle函数——paddle.ones_like

    分类目录:<深入浅出PaddlePaddle函数>总目录 相关文章: · 深入浅出PaddlePaddle函数--paddle.Tensor · 深入浅出PaddlePaddle函数--p ...

  3. 深入浅出PaddlePaddle函数——paddle.arange

    分类目录:<深入浅出PaddlePaddle函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.range · 深入浅出Pytorch函数--torch.arange ...

  4. 深入浅出PaddlePaddle函数——paddle.numel

    分类目录:<深入浅出PaddlePaddle函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.size · 深入浅出Pytorch函数--torch.numel · ...

  5. 深入浅出TensorFlow2函数——tf.constant

    分类目录:<深入浅出TensorFlow2函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.constant · 深入浅出TensorFlow2函数--tf.Ten ...

  6. 深入浅出Pytorch函数——torch.arange

    分类目录:<深入浅出Pytorch函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.range · 深入浅出Pytorch函数--torch.arange · 深入 ...

  7. 深入浅出Pytorch函数——torch.exp

    分类目录:<深入浅出Pytorch函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.exp · 深入浅出TensorFlow2函数--tf.math.exp · 深 ...

  8. 深入浅出Pytorch函数——torch.numel

    分类目录:<深入浅出Pytorch函数>总目录 相关文章: · 深入浅出TensorFlow2函数--tf.size · 深入浅出Pytorch函数--torch.numel · 深入浅出 ...

  9. 深入浅出TensorFlow2函数——tf.data.Dataset.batch

    分类目录:<深入浅出TensorFlow2函数>总目录 语法 batch(batch_size, drop_remainder=False, num_parallel_calls=None ...

最新文章

  1. 06.系统编程-3.进程VS线程比较
  2. Redis分布式锁(ServiceStack.Redis实现)
  3. 如何在Java中生成比特币钱包地址
  4. 常用c语言函数实现,常用的C语言库函数实现
  5. PHP 通用检测函数集
  6. 图片处理应用:固定容器缩略图实现
  7. MySQL-快速入门(13)MySQL日志
  8. windows下WDK创建免费的测试证书,并签名windows驱动文件(附带测试效果)
  9. 台式机与笔记本辐射谁大
  10. proc 文件的创建和读写
  11. xposed模块编写教程_新手不要再被误导!这是一篇最新的Xposed模块编写教程
  12. 想要分离歌曲内的伴奏?轻松搞定
  13. 垃圾收集器回收种类 以及七种垃圾收集器
  14. python画图:小圆覆盖大圆问题
  15. Python爬取房价
  16. 转载:一篇文章看明白 Android 系统启动时都干了什么
  17. 酷!我把废旧的Android手机改造成了Linux服务器
  18. 【转】win10录屏快捷键报错显示需要新应用打开ms-gamingoverlay
  19. 股票数据API接口合集:腾讯股票接口、麦蕊智数股票接口、和讯网股票接口、新浪股票接口、雪球股票数据、网易股票数据
  20. linux 820m驱动下载,下载:NVIDIA显卡最新177.67版驱动For Linux

热门文章

  1. 记录成功用bkcrack分别对压缩包进行明文攻击
  2. 数字签名中公钥和私钥是什么?
  3. P3801 红色的幻想乡(树状数组)
  4. mfc 中连接sql server2005
  5. 增长的接力棒——从营业收入拆解看商业模式
  6. 流程图形化-流程拆分(DAG(有向无环图)计算所有的路径)
  7. 谨以此片献给新中国60华诞
  8. 讲讲 Maven 依赖
  9. 授时服务器 微软,Windows10搭建NTP授时服务器
  10. vray学习笔记(1)vray介绍