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: A Tensor.
  • axis: 0-D (scalar). Specifies the dimension index at which to expand the shape of input. Must be in the range [-rank(input) - 1, rank(input)].
  • name: The name of the output Tensor.
  • dim: 0-D (scalar). Equivalent to axis, to be deprecated.

Returns:

Tensor with the same data as input, but its shape has an additional dimension of size 1 added.

Raises:

  • ValueError: if both dim and axis are specified.

expand_dims的更多相关文章

  1. tensorflow 笔记14:tf.expand_dims和tf.squeeze函数

    tf.expand_dims和tf.squeeze函数 一.tf.expand_dims() Function tf.expand_dims(input, axis=None, name=None, ...

  2. tf.expand_dims 来增加维度

    主要是因为tflearn官方的例子总是有embeding层,去掉的话要conv1d正常工作,需要加上expand_dims network = input_data(shape=[None, 100] ...

  3. 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 ...

  4. expand_dims函数

    >>> x = np.array([1,2]) >>> x.shape (2,) >>> y = np.expand_dims(x, axis=0 ...

  5. 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], ...

  6. 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 ...

  7. numpy-np.ceil,np.floor,np.expand_dims方法

    np.ceil(多维数组):对多维数组的各个数向上取整 np.floor(多维数组):对多维数组的各个数向下取整 np.expand_dims(x,axis = 0):在x的第一维度上插入一个维度,a ...

  8. 03-numpy-笔记-expand_dims

    >>> x = np.array([[1,2,3],[4,5,6]]) >>> x.shape (2, 3) >>> np.expand_dims ...

  9. tf.expand_dims和tf.squeeze函数

    from http://blog.csdn.net/qq_31780525/article/details/72280284 tf.expand_dims() Function tf.expand_d ...

随机推荐

  1. JAVA基础——设计模式之装饰者模式

    装饰模式 : 对新房进行装修并没有改变房屋的本质,但它可以让房子变得更漂亮.更温馨.更实用.    在软件设计中,对已有对象(新房)的功能进行扩展(装修).    把通用功能封装在装饰器中,用到的地方 ...

  2. 获取本地验证码cookie

    window.document.onkeydown = function (evt) { evt = (evt) ? evt : window.event; if (evt.keyCode) { if ...

  3. nodejs初探

    var http= require('http');var server= http.createServer(function(req,res){ res.writeHead(200,{" ...

  4. POJ 1995 (快速幂) 求(A1B1+A2B2+ ... +AHBH)mod M

    Description People are different. Some secretly read magazines full of interesting girls' pictures, ...

  5. 集训第四周(高效算法设计)A题 Ultra-QuickSort

    原题poj 2299:http://poj.org/problem?id=2299 题意,给你一个数组,去统计它们的逆序数,由于题目中说道数组最长可达五十万,那么O(n^2)的排序算法就不要再想了,归 ...

  6. Codeforces Round #413 B T-shirt buying (STL set)

    链接:http://codeforces.com/contest/799/problem/B 题意: 给定n件衣服,对于第i(1<i<=n)件衣服,分别有价格pi,前颜色ai,后颜色bi三 ...

  7. popup介绍

    一.作用 用于使浏览器自动生成弹窗 二.示例 1.新建Django项目,新建APP:app01, 项目根目录下新建文件夹static 2.静态文件配置,在settings.py中配置static: 3 ...

  8. Git 与其他系统 - Git 与 Subversion

    https://git-scm.com/book/zh/v1/Git-%E4%B8%8E%E5%85%B6%E4%BB%96%E7%B3%BB%E7%BB%9F-Git-%E4%B8%8E-Subve ...

  9. C# 3.0特性

    C# 3.0的扩展特性主要包括以下几点,我们在后面也会按照这个顺序进行介绍:1.隐式局部变量(implicitly typed local variables),通过初始化该局部变量的表达式自动推断出 ...

  10. 详解js变量声明提升

    之前一直觉会认为javascript代码执行是由上到下一行行执行的.自从看了<你不知道的JS>后发现这个观点并不完全正确.先来给大家举一个书本上的的例子: var a='hello wor ...