示例:

import tensorflow as tf
lenth = tf.reshape(30,shape=[-1])  #变成一维张量
lenth2 = tf.reshape(30,shape=[])  #变成标量了
lenth3 = tf.reshape([30],shape=[])  #变成标量了
with tf.Session() as sess:sess.run(tf.global_variables_initializer())a = sess.run(lenth)b = sess.run(lenth2)c = sess.run(lenth3)
print(a,b,c)[30] 30 30

变成一维的,但一维与标量确理解错了;标量可以理解为0维;

标量可以用shape=[]参数定义

If one component of `shape` is the special value -1, the size of that dimensionis computed so that the total size remains constant.  In particular, a `shape`of `[-1]` flattens into 1-D.  At most one component of `shape` can be -1.If `shape` is 1-D or higher, then the operation returns a tensor with shape`shape` filled with the values of `tensor`. In this case, the number of elementsimplied by `shape` must be the same as the number of elements in `tensor`.For example:```# tensor 't' is [1, 2, 3, 4, 5, 6, 7, 8, 9]# tensor 't' has shape [9]reshape(t, [3, 3]) ==> [[1, 2, 3],[4, 5, 6],[7, 8, 9]]# tensor 't' is [[[1, 1], [2, 2]],#                [[3, 3], [4, 4]]]# tensor 't' has shape [2, 2, 2]reshape(t, [2, 4]) ==> [[1, 1, 2, 2],[3, 3, 4, 4]]# tensor 't' is [[[1, 1, 1],#                 [2, 2, 2]],#                [[3, 3, 3],#                 [4, 4, 4]],#                [[5, 5, 5],#                 [6, 6, 6]]]# tensor 't' has shape [3, 2, 3]# pass '[-1]' to flatten 't'reshape(t, [-1]) ==> [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]# -1 can also be used to infer the shape# -1 is inferred to be 9:reshape(t, [2, -1]) ==> [[1, 1, 1, 2, 2, 2, 3, 3, 3],[4, 4, 4, 5, 5, 5, 6, 6, 6]]# -1 is inferred to be 2:reshape(t, [-1, 9]) ==> [[1, 1, 1, 2, 2, 2, 3, 3, 3],[4, 4, 4, 5, 5, 5, 6, 6, 6]]# -1 is inferred to be 3:reshape(t, [ 2, -1, 3]) ==> [[[1, 1, 1],[2, 2, 2],[3, 3, 3]],[[4, 4, 4],[5, 5, 5],[6, 6, 6]]]# tensor 't' is [7]# shape `[]` reshapes to a scalarreshape(t, []) ==> 7```

tf.reshape(inputs, [-1,dim])的理解相关推荐

  1. tf.reshape的-1的错误理解

    一直以为reshape(-1,)会变成一维的,然后变成一个标量: import tensorflow as tf lenth = tf.reshape(30,shape=[-1]) lenth2 = ...

  2. tensorflow 之 tf.reshape 之 -1

    最近压力好大,写点东西可能对心情有好处. reshape即把矩阵的形状变一下,这跟matlab一样的,但如果参数是-1的话是什么意思呢? 看一下例子哈: . . . In [21]: tensor = ...

  3. tf.reshape 和 tf.transpose 用法

    import tensorflow as tf x= tf.constant([[2,3],[4,5],[6,7]],tf.int32) print(x.numpy()) [[2 3][4 5][6 ...

  4. 【tensorflow】tf.reshape函数说明:重塑张量

    转载 [471]tf.reshape函数说明_周小董-CSDN博客 https://blog.csdn.net/xc_zhou/article/details/85342542 函数原型: tf.re ...

  5. tensorflow 之 最近用到的几个小操作tf.reshape,tf.convert_to_tensor,tf.where

    1.tf.reshape() #调整tensor的形状 img = .... img_res = tf.reshape(img, [-1]) 着重记录是shape=[-1]时,相当于flatten操作 ...

  6. TensorFlow学习笔记(十八)tf.reshape矩阵变形

    tf.reshape(tensor, shape, name=None) 矩阵变形是常用的操作,在Tensorflow中调用方式有多种,例如: 1. tf.reshape tf.reshape(L3, ...

  7. tf.reshape()

    _image = tf.reshape(x, [-1,28, 28, 1]) # -1表示任意数量的样本数,大小为28x28深度为一的张量 # 可以忽略(其实是用深度为28的,28x1的张量,来表示2 ...

  8. tf.shape()和tf.reshape()

    一.tf.shape() tf.shape(input,name=None,out_type=tf.int32) 参数 (1)input:输入张量或稀疏张量: (2)name:命名: (3)out_t ...

  9. Pytorch中dim的理解

    dim的定义 dim 表示维度 x = torch.randn(2, 3, 3)print(x) print(x.size()) print(x.dim()) 输出: tensor([[[-1.694 ...

最新文章

  1. java多线程问题_【java 多线程】多线程并发同步问题及解决方法
  2. 解决xtraFinder在EI下不能使用问题
  3. Three.js入门
  4. 基于Asp.Net Core打造轻量级内部服务治理RPC(二 远程服务设计)
  5. 谈谈这些年前端的变化
  6. yolov4 开发环境搭建_YOLOv4 的各种新实现、配置、测试、训练资源汇总
  7. 信息学奥赛一本通(1266:【例9.10】机器分配)
  8. 2013-07-29 IT 要闻速记快想
  9. 区块链 Fisco bcos 智能合约(17)-区块链的速度困境:“贵”在信任,“慢”得其所
  10. java中连接字符串_Java中几种方式连接字符串的方法
  11. python通讯录文件读取_python通用读取vcf文件的类(可以直接复制粘贴使用)
  12. git生成key以及小乌龟git不需要密码
  13. 随笔分类 - PowerShell
  14. 中心极限与大数定理律的关系_21厦大数学考研 | 数列与函数极限复习建议!
  15. 天龙八部TLBB系列 - 网单服务端各目录文件说明【超详细】
  16. RF自动化测试框架(一)
  17. 利用计算机审计新闻,计算机审计显身手 审计员钻出账本堆被审单位麻烦减少...
  18. 苹果输入法怎么换行_朋友圈不折叠的N种方法安卓苹果通用
  19. 实现加减乘除任意组合的语法解析
  20. pdf 压缩怎么做?三种办法可供选择

热门文章

  1. boost::mpi模块在序列化数据上测试 any_source
  2. boost::hana::type_foldl1用法的测试程序
  3. boost::clustering_coefficient用法的测试程序
  4. GDCM:gdcm::Reader的测试程序
  5. GDCM:打印dicom文件的LookupTable的测试程序
  6. Boost:排序的bimap双图的测试程序
  7. Boost:异步操作,需要boost :: asio :: async_initiate函数的测试程序
  8. Boost:cpu时间的实例
  9. ITK:二维高斯混合模型期望最大化
  10. VTK:简单操作之RandomSequence