expand_dims
tf.expand_dims | TensorFlow https://tensorflow.google.cn/api_docs/python/tf/expand_dims
tf.expand_dims
tf.expand_dims(
input,
axis=None,
name=None,
dim=None
)
Defined in tensorflow/python/ops/array_ops.py
.
See the guide: Tensor Transformations > Shapes and Shaping
Inserts a dimension of 1 into a tensor's shape.
Given a tensor input
, this operation inserts a dimension of 1 at the dimension index axis
of input
's shape. The dimension index axis
starts at zero; if you specify a negative number for axis
it is counted backward from the end.
This operation is useful if you want to add a batch dimension to a single element. For example, if you have a single image of shape [height, width, channels]
, you can make it a batch of 1 image with expand_dims(image, 0)
, which will make the shape [1, height, width, channels]
.
Other examples:
# 't' is a tensor of shape [2]
tf.shape(tf.expand_dims(t, 0)) # [1, 2]
tf.shape(tf.expand_dims(t, 1)) # [2, 1]
tf.shape(tf.expand_dims(t, -1)) # [2, 1]
# 't2' is a tensor of shape [2, 3, 5]
tf.shape(tf.expand_dims(t2, 0)) # [1, 2, 3, 5]
tf.shape(tf.expand_dims(t2, 2)) # [2, 3, 1, 5]
tf.shape(tf.expand_dims(t2, 3)) # [2, 3, 5, 1]
This operation requires that:
-1-input.dims() <= dim <= input.dims()
This operation is related to squeeze()
, which removes dimensions of size 1.
Args:
input
: ATensor
.axis
: 0-D (scalar). Specifies the dimension index at which to expand the shape ofinput
. Must be in the range[-rank(input) - 1, rank(input)]
.name
: The name of the outputTensor
.dim
: 0-D (scalar). Equivalent toaxis
, to be deprecated.
Returns:
A Tensor
with the same data as input
, but its shape has an additional dimension of size 1 added.
Raises:
ValueError
: if bothdim
andaxis
are specified.
expand_dims的更多相关文章
- tensorflow 笔记14:tf.expand_dims和tf.squeeze函数
tf.expand_dims和tf.squeeze函数 一.tf.expand_dims() Function tf.expand_dims(input, axis=None, name=None, ...
- tf.expand_dims 来增加维度
主要是因为tflearn官方的例子总是有embeding层,去掉的话要conv1d正常工作,需要加上expand_dims network = input_data(shape=[None, 100] ...
- tensorflow 基本函数(1.tf.split, 2.tf.concat,3.tf.squeeze, 4.tf.less_equal, 5.tf.where, 6.tf.gather, 7.tf.cast, 8.tf.expand_dims, 9.tf.argmax, 10.tf.reshape, 11.tf.stack, 12tf.less, 13.tf.boolean_mask
1. tf.split(3, group, input) # 拆分函数 3 表示的是在第三个维度上, group表示拆分的次数, input 表示输入的值 import tensorflow ...
- expand_dims函数
>>> x = np.array([1,2]) >>> x.shape (2,) >>> y = np.expand_dims(x, axis=0 ...
- Shape,expand_dims,slice基本用法
import tensorflow as tf t = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]], [[5, 5, 5], ...
- pytorch中torch.unsqueeze()函数与np.expand_dims()
numpy.expand_dims(a, axis) Expand the shape of an array. Insert a new axis that will appear at the a ...
- numpy-np.ceil,np.floor,np.expand_dims方法
np.ceil(多维数组):对多维数组的各个数向上取整 np.floor(多维数组):对多维数组的各个数向下取整 np.expand_dims(x,axis = 0):在x的第一维度上插入一个维度,a ...
- 03-numpy-笔记-expand_dims
>>> x = np.array([[1,2,3],[4,5,6]]) >>> x.shape (2, 3) >>> np.expand_dims ...
- tf.expand_dims和tf.squeeze函数
from http://blog.csdn.net/qq_31780525/article/details/72280284 tf.expand_dims() Function tf.expand_d ...
随机推荐
- 第1节 yarn:14、yarn集群当中的三种调度器
yarn当中的调度器介绍: 第一种调度器:FIFO Scheduler (队列调度器) 把应用按提交的顺序排成一个队列,这是一个先进先出队列,在进行资源分配的时候,先给队列中最头上的应用进行分配资源 ...
- filezilla server FTP 安装报错 "could not load TLS network. Aborting start of administration interface"
filezilla server FTP 安装报错 "could not load TLS network. Aborting start of administration inter ...
- 计算几何——认识基本object:点、线、面 。
认识基本object:点.线.面 一.点 点用P(x, y)来表示:如: typedef pair<double, double> _pair; _pair point[MAXN]; 二 ...
- Python入门之类(class)
面向对象三大特性 面向对象的三大特性是指:封装.继承和多态. 一.封装 封装,顾名思义就是将内容封装到某个地方,以后再去调用被封装在某处的内容. 所以,在使用面向对象的封装特性时,需要: 将内容封装到 ...
- delphi clipboard
判断clipboard里的格式: if CliPBoard.HasFormat(CF_TEXT) then EdIT1.Text := CliPBoard.AsText ...
- list嵌套,int与str的用法,replace
#*************************replace(待改,改动值),返回很重要 A = [['libai',89]] A[0][0]=A[0][0].replace('a','af') ...
- Vertex&Frag
一.Vertex&Frag 包含Vertex&Fragment 的Shader叫做顶点&像素着色器,在Vertex的功能函数中,我们侧重于几何计算,如纹理坐标,顶点坐标等:在F ...
- 一个ajax实例
一个ajax实例 html <!DOCTYPE html> <html lang="zh-cn"> <head> <meta ch ...
- Qt笔记——连接第三方库&用libZPlay库获取音频文件的艺术家、专辑等信息
连接第三方库libZPlay 概述 需要.a/.lib ,.h , .dll 三个文件 官网下载 http://libzplay.sourceforge.net/ import .h 链接 .a 放入 ...
- 3D模型
题目描述 一座城市建立在规则的n×m网格上,并且网格均由1×1正方形构成.在每个网格上都可以有一个建筑,建筑由若干个1×1×1的立方体搭建而成(也就是所有建筑的底部都在同一平面上的).几个典型的城市模 ...