Tensorflow之改变tensor形状

https://www.tensorflow.org/versions/r0.12/api_docs/python/array_ops.html#reshape

例子:

# 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 scalar
reshape(t, []) ==> 7
时间: 2024-12-20 20:36:13

Tensorflow之改变tensor形状的相关文章

C#设置鼠标在控件上面时,改变光标形状

//设置鼠标在控件上面时,改变光标形状 private void pictureBox_macroLogo_MouseHover(object sender, System.EventArgs e) { this.Cursor = Cursors.Hand; } private void pictureBox_macroLogo_MouseLeave(object sender, System.EventArgs e) { this.Cursor = Cursors.Default; }

Tensorflow之Tensor形状变换和剪切组合

https://www.tensorflow.org/versions/r0.12/api_docs/python/array_ops/slicing_and_joining

点击帮助按钮改变鼠标形状

$(function () { $('html *:not(#btn_helper_)').click(function (e) { hepler = false; $("html").css({ cursor: "url(''),auto" }); //e.stopPropagation(); }); $("#btn_helper_").click(function (e) { $("html").css({ cursor:

改变字符形状和颜色NSMutableAttributedString

NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:@"我还是一样帅"]; //设置文字颜色 [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 1)]; [str addAttribute:NSForegroundColorAttribu

PyTorch安装及基础

PyTorch安装: https://pytorch.org/get-started/locally/ PyTorch基础: 张量:包括零维(常数),一维(数组/列表/元组),二维(矩阵)...... 张量的创建: torch.tensor(list/array/tuple) #把数组/列表/集合转化为张量 torch.ones([2,3]) #创建形状为[2,3]的,元素均为1的张量 torch.zeros([2,3]) #创建形状为[2,3]的,元素均为0的张量 torch.empty([2

机器学习-Tensorflow之Tensor和Dataset学习

好了,咱们今天终于进入了现阶段机器学习领域内最流行的一个框架啦——TensorFlow.对的,这款由谷歌开发的机器学习框架非常的简单易用并且得到了几乎所有主流的认可,谷歌为了推广它的这个框架甚至单独开辟了免费学习这个框架的视频教程,可惜这些教程都是基于TensorFlow1.0版本的,一直没有更新.现在都是TensorFlow2.0版本了,其中的开发的API的变化非常非常大,很多都是不兼容的,非常坑,如果大家还是觉得要跳坑,我不拦着哈.它的应用的官方视频教程的地址是https://develop

TensorFlow 初探

最近致力于深度学习,希望在移动领域能够找出更多的应用点.其中TensorFlow作为目前的一个热点值得我们重点关注. 机器学习 机器学习是人工智能的一个分支,也是用来实现人工只能的一种方法.简单来说,机器学习就是通过算法,使得机器能从大量历史数据中学习规律,从而对新的样本做智能识别或对未来做预测,与传统的使用特定指令集手写软件不同,我们使用大量数据和算法来"训练"机器,由此带来机器学习如何完成任务.从1980年代末期以来,机器学习的发展大致经历了两次浪潮:浅层学习(Shallow Le

tensorflow函数

TensorFlow 将图形定义转换成分布式执行的操作, 以充分利用可用的计算资源(如 CPU 或 GPU.一般你不需要显式指定使用 CPU 还是 GPU, TensorFlow 能自动检测.如果检测到 GPU, TensorFlow 会尽可能地利用找到的第一个 GPU 来执行操作. 并行计算能让代价大的算法计算加速执行,TensorFlow也在实现上对复杂操作进行了有效的改进.大部分核相关的操作都是设备相关的实现,比如GPU.下面是一些重要的操作/核: 操作组 操作 Maths Add, Su

Tensorflow一些常用基本概念与函数

转载: https://blog.csdn.net/lenbow/article/details/52152766 1.tensorflow的基本运作 为了快速的熟悉TensorFlow编程,下面从一段简单的代码开始: import tensorflow as tf #定义'符号'变量,也称为占位符 a = tf.placeholder("float") b = tf.placeholder("float")   y = tf.mul(a, b) #构造一个op节点