TensorFlow tensor的拼接实例

yipeiwu_com5年前Python基础

TensorFlow提供两种类型的拼接:

tf.concat(values, axis, name='concat'):按照指定的已经存在的轴进行拼接
tf.stack(values, axis=0, name='stack'):按照指定的新建的轴进行拼接
t1 = [[1, 2, 3], [4, 5, 6]]
t2 = [[7, 8, 9], [10, 11, 12]]
tf.concat([t1, t2], 0) ==> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
tf.concat([t1, t2], 1) ==> [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12]]
tf.stack([t1, t2], 0) ==> [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]
tf.stack([t1, t2], 1) ==> [[[1, 2, 3], [7, 8, 9]], [[4, 5, 6], [10, 11, 12]]]
tf.stack([t1, t2], 2) ==> [[[1, 7], [2, 8], [3, 9]], [[4, 10], [5, 11], [6, 12]]]
t1 = [[1, 2, 3], [4, 5, 6]]
t2 = [[7, 8, 9], [10, 11, 12]]
tf.concat([t1, t2], 0) # [2,3] + [2,3] ==> [4, 3]
tf.concat([t1, t2], 1) # [2,3] + [2,3] ==> [2, 6]
tf.stack([t1, t2], 0) # [2,3] + [2,3] ==> [2*,2,3]
tf.stack([t1, t2], 1) # [2,3] + [2,3] ==> [2,2*,3]
tf.stack([t1, t2], 2) # [2,3] + [2,3] ==> [2,3,2*]

以上这篇TensorFlow tensor的拼接实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

django-初始配置(纯手写)详解

我们通过django-admin startproject zhuyu命令创建好项目后,在pycharm中打开 我们需要在在该项目中,配置一些相关操作。 1、template(存放模板的...

python print输出延时,让其立刻输出的方法

一句print("ni hao"),很久看不见,怎么让python print能立刻输出呢。 因为python默认是写入stdout缓冲的,使用-u参数启动python,就会立刻输出了。...

python如何压缩新文件到已有ZIP文件

本文为大家分享了python压缩新文件到已有ZIP文件的具体代码,供大家参考,具体内容如下 要点在于使用Python标准库zipfile创建压缩文件时,如果使用'a'模式时,可以追加新内...

python中单例常用的几种实现方法总结

前言 最近这两天在看自己之前写的代码,所以正好把用过的东西整理一下,单例模式,在日常的代码工作中也是经常被用到, 所以这里把之前用过的不同方式实现的单例方式整理一下 什么是单例? 确保...

python中使用iterrows()对dataframe进行遍历的实例

python中使用iterrows()对dataframe进行遍历的实例

假设我们有一个很简单的OTU表: 现在对这个表格进行遍历,一般写法为: import pandas as pd otu = pd.read_csv("otu.txt",sep="\...