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使用JNA方式调用DLL(动态链接库)(原创,装载请注明出处)

    Java使用JNA调用DLL 1.准备 1.JDK环境 2.Eclipse 3.JNA包 下载JNA包: (1).JNA的Github:https://github.com/java-native-a ...

  2. 零基础入门学习Python(26)--字典:当索引不好用时2

    知识点 删除字典元素 能删单一的元素也能清空字典,清空只需一项操作. 显示删除一个字典用del命令,如下: >>> dict1 = {'a':1,'b':2,'c':3} >& ...

  3. WSS、SSL 和 https 之间的关系

    SSL SSL(Secure Socket Layer,安全套接层) 简单来说是一种加密技术, 通过它, 我们可以在通信的双方上建立一个安全的通信链路, 因此数据交互的双方可以安全地通信, 而不需要担 ...

  4. java实现扫二维码登录功能

    哈哈哈 http://blog.sina.com.cn/s/blog_7f416edf0102vb8h.html http://blog.sina.com.cn/s/blog_7f416edf0102 ...

  5. 编程数学-∑(求和符号)-Sigma

    百度百科:∑ 在数学中,我们把它作为求和符号使用. 大写Σ用于数学上的总和符号,比如:∑Pi,其中i=1,2,...,T,即为求P1 + P2 + ... + PT的和.小写σ用于统计学上的标准差.西 ...

  6. MVC系统学习5——验证

    其实关于Mvc的验证在上一篇已经有讲过一些了,可以通过在我们定义的Model上面添加相应的System.ComponentModel.DataAnnotations空间下的验证属性.在服务器端通过Mo ...

  7. [luoguP2827] 蚯蚓(堆?队列!)

    传送门 35分做法 用堆来取最大值,暴力更新其余数的值. 65~85分做法 还是用堆来取最大值,其余的数增加可以变成新切开的两个数减少,最后统一加上一个数. #include <queue> ...

  8. hdu 1179最大匹配

    #include<stdio.h> #include<string.h> #define N 200 int map[N][N],visit[N],link[N],n,m; i ...

  9. poj 1733离散化(map)+并查集

    http://blog.sina.com.cn/s/blog_803d08c00100y2yy.html #include<stdio.h> #include<iostream> ...

  10. 【bzoj2152】聪聪可可 点分治

    [bzoj2152]聪聪可可 2014年9月7日3,5472 Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是 ...