tf.unstack(value, num=None, axis=0, name='unstack')
Unpacks the given dimension of a rank-`R` tensor into rank-`(R-1)` tensors.
Unpacks `num` tensors from `value` by chipping it along the `axis` dimension.
Args: value:A rank `R > 0` `Tensor` to be unstacked.
num: An `int`. The length of the dimension `axis`. Automatically inferred
//一个“int”。尺寸“轴”的长度。自动推断为“无”(默认)。
if`None` (the default).
axis: An `int`. The axis to unstack along. Defaults to the first
dimension. Supports negative indexes.
name:A name for the operation (optional).
Returns:
The list of `Tensor` objects unstacked from `value`. Raises: ValueError:If`num` is unspecified and cannot be inferred.
ValueError:If`axis` is out of the range [-R, R).
import tensorflow as tf
a = tf.constant([1,2,3])
b = tf.constant([4,5,6])
c = tf.stack([a,b],axis=1)
d = tf.unstack(c,axis=0)
e = tf.unstack(c,axis=1)
print(c.get_shape())
with tf.Session() as sess:
print(sess.run(c))
print(sess.run(d))
print(sess.run(e))
(3, 2)
[[1 4]
[2 5]
[3 6]]
[array([1, 4]), array([2, 5]), array([3, 6])]
[array([1, 2, 3]), array([4, 5, 6])]
numpy.delete删除行或列
import numpy as np
A = np.delete(B, 2, axis=0) # 删除B的第三行
B = np.delete(C, 1, axis=1) # 删除C的第2列
numpy.concatenate numpy.concatenate((a1, a2, …), axis=0) Join a sequence of arrays along an existing axis. Parameters: a1, a2, … : sequence of array_like The arrays must have the same shape, except in the dimension corresponding to axis (the first, by default). axis : int, optional The axis along which the arrays will be joined. Default is 0. Returns: res : ndarray The concatenated array.
Help on function mergeinmodule keras.legacy.layers:
merge(inputs, mode='sum', concat_axis=-1, dot_axes=-1, output_shape=None, output_mask=None, arguments=None, name=None)
Functional merge, to apply to Keras tensors (NOT layers).
Returns a Keras tensor.
# Example
# Arguments
mode: String or lambda/function. If string, must be one
of: 'sum', 'mul', 'concat', 'ave', 'cos', 'dot', 'max'.
If lambda/function, it should take asinput a list of tensors
and return a single tensor.
concat_axis: Integer, axis to use in mode `concat`.
dot_axes: Integeror tuple of integers,
axes to use in mode `dot`or`cos`.
output_shape: Shape tuple (tuple of integers), or lambda/function
to compute output_shape (onlyifmerge mode is a lambda/function).
If the latter case, it should take asinput a list of shape tuples
(1:1 mapping toinput tensors) and return a single shape tuple,
including the batch size
(same convention as the `compute_output_shape` method of layers).
node_indices: Optional list of integers containing
the output node index foreachinput layer
(incasesomeinput layers have multiple output nodes).
will defaultto an array of0s ifnot provided.
tensor_indices: Optional list of indices ofoutput tensors
to consider for merging
(incasesomeinput layer node returns multiple tensors).
defconcatenate(inputs, axis=-1, **kwargs):"""Functional interface to the `Concatenate` layer.
# Arguments
inputs: A list of input tensors (at least 2).
axis: Concatenation axis.
**kwargs: Standard layer keyword arguments.
# Returns
A tensor, the concatenation of the inputs alongside axis `axis`.
"""return Concatenate(axis=axis, **kwargs)(inputs)
x = layers.concatenate(
[branch1x1, branch5x5, branch3x3dbl, branch_pool],
axis=channel_axis,
name='mixed1')
mxnet.ndarray.concat(*data, **kwargs)
x = [[1,1],[2,2]]
y = [[3,3],[4,4],[5,5]]
z = [[6,6], [7,7],[8,8]]
concat(x,y,z,dim=0) = [[ 1., 1.],
[ 2., 2.],
[ 3., 3.],
[ 4., 4.],
[ 5., 5.],
[ 6., 6.],
[ 7., 7.],
[ 8., 8.]]
Note that you cannot concat x,y,z along dimension 1 since dimension
0 is not the same for all the input arrays.
concat(y,z,dim=1) = [[ 3., 3., 6., 6.],
[ 4., 4., 7., 7.],
[ 5., 5., 8., 8.]]
Parameters:
data (Symbol[]) – List of arrays to concatenate
dim (int, optional, default='1') – the dimension to be concated.
name (string, optional.) – Name ofthe resulting symbol.
Returns:
The result symbol.
Return type:
Symbol
Examples
Concat two (or more) inputs along a specific dimension:
>>> a = Variable('a')
>>> b = Variable('b')
>>> c = Concat(a, b, dim=1, name='my-concat')
>>> c
>>> SymbolDoc.get_output_shape(c, a=(128, 10, 3, 3), b=(128, 15, 3, 3))
{'my-concat_output': (128L, 25L, 3L, 3L)}
Parameters:
data (Symbol) – Source input
axis (int, required) – Axis along which to be sliced, supports negative indexes.
begin (int, required) – The beginning index along the axis to be sliced, supports negative indexes.
end (int or None, required) – The ending index along the axis to be sliced, supports negative indexes.
name (string, optional.) – Name of the resulting symbol.
Returns:
The result symbol.
Return type:
Examples:
x = [[ 1., 2., 3., 4.],
[ 5., 6., 7., 8.],
[ 9., 10., 11., 12.]]
slice_axis(x, axis=0, begin=1, end=3) = [[ 5., 6., 7., 8.],
[ 9., 10., 11., 12.]]
slice_axis(x, axis=1, begin=0, end=2) = [[ 1., 2.],
[ 5., 6.],
[ 9., 10.]]
slice_axis(x, axis=1, begin=-3, end=-1) = [[ 2., 3.],
[ 6., 7.],
[ 10., 11.]]