一直以为reshape(-1,)会变成一维的,然后变成一个标量;

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的-1的错误理解相关推荐

  1. tf.reshape(inputs, [-1,dim])的理解

    示例: import tensorflow as tf lenth = tf.reshape(30,shape=[-1]) #变成一维张量 lenth2 = tf.reshape(30,shape=[ ...

  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. 计算机专业的会修电脑吗,常被错误理解的三大专业,计算机专业会修电脑,机械工程很是离谱...

    常被错误理解的三大专业,计算机专业会修电脑,机械工程很是离谱 在大学里有一些专业是经常被人误解,在生活中也是闹出了很多笑话,大学生对此也是很无奈,只能是和别人一遍又一遍去解释,你有没有遇到过类似的情况 ...

最新文章

  1. AAC_LC用LATM封装header信息解析 Audio Specific Config格式分析
  2. 开发日记-20190915 关键词 汇编语言王爽版 第九章
  3. C语言优先级——取反和移位
  4. 处理时间_2_计算两个时间列的差值
  5. selenium python 安装
  6. 机房收费系统的合作版
  7. Object类 java 1614965390
  8. C中位域结合对齐(pragma)的例子及解释
  9. 边缘设备上的实时AI人员检测:使用预先训练的SSD模型检测人员
  10. 两个字符串 char* a, char* b,输出b在a中的位置次序。
  11. 求解出能被5整除的正整数的乘积_事业单位数量关系:巧用“整除”求解数量关系...
  12. 数据优化 | CnOpenData中国工业企业绿色专利及引用被引用数据
  13. 会员数据化运营应用场景与分析模型
  14. [渝粤教育] 中国地质大学 工业卫生技术 复习题
  15. cesium天气(晴、雨、雪、雾)
  16. 关于canvas生成图片的方法
  17. java jpress,JPress导入Eclipse
  18. 2022-2028全球与中国汽车软内饰材料市场现状及未来发展趋势
  19. 微信分享功能踩坑过程
  20. 如何判断视频的比例(4:3/16:9)和分辨率?

热门文章

  1. html无间隔字幕滚动,js实现文字超过显示宽度每间隔1s自动向左滚动显示
  2. 深度学习网络backbone?head、neck、bottleneck、GAP、Embedding、pretext task、downstream task、temperature parameter
  3. C语言linux getopt_long()函数(命令行解析)(getopt、getopt_long_only)(短选项 -,长选项 --)(option结构体)(optind、optarg变量)
  4. yolo标注的数据清洗
  5. python 如何计算代码块运行(执行)时间?time() time.time() time.clock() 区别
  6. 静态页面cors跨域问题
  7. mpstat 命令查看所有CPU核信息
  8. linux多网卡bind发送数据,Linux系统多网卡绑定实战
  9. WINCE串口通讯经验小结
  10. 在EXT中向弹窗传值或者对象