def compress(condition, x, axis=None):
"""
Return selected slices of an array along given axis.
It returns the input tensor, but with selected slices along a given axis
retained. If no axis is provided, the tensor is flattened.
Corresponds to numpy.compress
.. versionadded:: 0.7
Parameters
----------
x
Input data, tensor variable.
condition
1 dimensional array of non-zero and zero values
corresponding to indices of slices along a selected axis.
Returns
-------
object
`x` with selected slices.
"""
indices = theano.tensor.basic.flatnonzero(condition)
return x.take(indices, axis=axis)
评论列表
文章目录