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 bothdimandaxisare 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 ...
随机推荐
- CSS 全局样式
设置全局 CSS 样式:基本的 HTML 元素均可以通过 class 设置样式并得到增强效果:还有先进的栅格系统.
- python3爬虫-爬取58同城上所有城市的租房信息
from fake_useragent import UserAgent from lxml import etree import requests, os import time, re, dat ...
- Data of Ch5 --Dual rotor
* Results *Conclusion*- little effect of rear rotor on Cp_1- Cp1 is independent of TI** TI effect on ...
- poj 1363 火车进站 (栈的应用)
Description There is a famous railway station in PopPush City. Country there is incredibly hilly. Th ...
- CEO的作用
看到有人讨论CEO的作用. 一个观点认为CEO有三大任务: 1)为公司确定战略,并与股东沟通 2)为公司其他职位找来合适的人员 3)保证公司随时有足够的钱 他认为,可能CEO会有其他的作用,但是这三点 ...
- 九度oj 题目1070:今年的第几天?
题目1070:今年的第几天? 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6832 解决:3779 题目描述: 输入年.月.日,计算该天是本年的第几天. 输入: 包括三个整数年(1< ...
- golang函数指针的效果
package main import ( "fmt" ) func fun1(key string) { fmt.Printf("fun11 key=%s\n" ...
- 《C语言程序设计(第四版)》阅读心得(三)
第八章 指针 1.一个变量的地址称为该变量的指针 一个专门用来存放另一变量的地址(即指针),称它为指针变量.指针变量的值是指针(即地址) 如上图2000是变量的指针,pointer是指针变量, 赋值 ...
- DBA的40条军规
DBA操作规范 1.涉及业务上的修改/删除数据,在得到业务方.CTO的邮件批准后方可执行,执行前提前做好备份,必要时可逆. 2.所有上线需求必须走工单系统,口头通知视为无效. 3.在对大表做表结构变更 ...
- 莫比乌斯反演套路一--令t=pd--BZOJ2820: YY的GCD
t<=10000组询问:有多少x,y,满足$x\epsilon [1,n],y\epsilon [1,m],(x,y)为质数$.n,m<=1e7. 首先式子列出来,f(i)--1<= ...