tensor.extra_ops
– Tensor Extra Ops¶
-
class
theano.tensor.extra_ops.
BinCountOp
(minlength=None)¶ Note
Deprecated Use bincount() instead. See function bincount for docstring.
-
compatible_type
= ('int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64')¶ Tuple of all compatible dtype for the parameter of this op.
-
-
class
theano.tensor.extra_ops.
CpuContiguous
(use_c_code='/usr/bin/g++')¶ Check to see if the input is c-contiguous, if it is, do nothing, else return a contiguous array.
-
class
theano.tensor.extra_ops.
Unique
(return_index=False, return_inverse=False, return_counts=False)¶ Wraps numpy.unique. This op is not implemented on the GPU.
Examples
>>> import numpy as np >>> import theano
>>> x = theano.tensor.vector() >>> f = theano.function([x], Unique(True, True, False)(x)) >>> f([1, 2., 3, 4, 3, 2, 1.]) [array([ 1., 2., 3., 4.]), array([0, 1, 2, 3]), array([0, 1, 2, 3, 2, 1, 0])]
>>> y = theano.tensor.matrix() >>> g = theano.function([y], Unique(True, True, False)(y)) >>> g([[1, 1, 1.0], (2, 3, 3.0)]) [array([ 1., 2., 3.]), array([0, 3, 4]), array([0, 0, 0, 1, 2, 2])]
-
theano.tensor.extra_ops.
bartlett
(M)¶ An instance of this class returns the Bartlett spectral window in the time-domain. The Bartlett window is very similar to a triangular window, except that the end points are at zero. It is often used in signal processing for tapering a signal, without generating too much ripple in the frequency domain.
New in version 0.6.
Parameters: M (integer scalar) – Number of points in the output window. If zero or less, an empty vector is returned. Returns: The triangular window, with the maximum value normalized to one (the value one appears only if the number of samples is odd), with the first and last samples equal to zero. Return type: vector of doubles
-
theano.tensor.extra_ops.
bincount
(x, weights=None, minlength=None, assert_nonneg=False)¶ Count number of occurrences of each value in array of ints.
The number of bins (of size 1) is one larger than the largest value in x. If minlength is specified, there will be at least this number of bins in the output array (though it will be longer if necessary, depending on the contents of x). Each bin gives the number of occurrences of its index value in x. If weights is specified the input array is weighted by it, i.e. if a value n is found at position i, out[n] += weight[i] instead of out[n] += 1.
Parameters: - x (1 dimension, nonnegative ints) –
- weights (array of the same shape as x with corresponding weights.) – Optional.
- minlength (A minimum number of bins for the output array.) – Optional.
- assert_nonneg (A flag that inserts an assert_op to check if) – every input x is nonnegative. Optional.
- versionadded (.) –
-
theano.tensor.extra_ops.
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
New in version 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: x with selected slices.
Return type: object
-
theano.tensor.extra_ops.
cumprod
(x, axis=None)¶ Return the cumulative product of the elements along a given axis.
Wraping of numpy.cumprod.
Parameters: - x – Input tensor variable.
- axis – The axis along which the cumulative product is computed. The default (None) is to compute the cumprod over the flattened array.
- versionadded (.) –
-
theano.tensor.extra_ops.
cumsum
(x, axis=None)¶ Return the cumulative sum of the elements along a given axis.
Wraping of numpy.cumsum.
Parameters: - x – Input tensor variable.
- axis – The axis along which the cumulative sum is computed. The default (None) is to compute the cumsum over the flattened array.
- versionadded (.) –
-
theano.tensor.extra_ops.
diff
(x, n=1, axis=-1)¶ Calculate the n-th order discrete difference along given axis.
The first order difference is given by out[i] = a[i + 1] - a[i] along the given axis, higher order differences are calculated by using diff recursively. Wraping of numpy.diff.
Parameters: - x – Input tensor variable.
- n – The number of times values are differenced, default is 1.
- axis – The axis along which the difference is taken, default is the last axis.
- versionadded (.) –
-
theano.tensor.extra_ops.
fill_diagonal
(a, val)¶ Returns a copy of an array with all elements of the main diagonal set to a specified scalar value.
New in version 0.6.
Parameters: - a – Rectangular array of at least two dimensions.
- val – Scalar value to fill the diagonal whose type must be compatible with that of array ‘a’ (i.e. ‘val’ cannot be viewed as an upcast of ‘a’).
Returns: - array – An array identical to ‘a’ except that its main diagonal is filled with scalar ‘val’. (For an array ‘a’ with a.ndim >= 2, the main diagonal is the list of locations a[i, i, ..., i] (i.e. with indices all identical).)
- Support rectangular matrix and tensor with more than 2 dimensions
- if the later have all dimensions are equals.
-
theano.tensor.extra_ops.
fill_diagonal_offset
(a, val, offset)¶ Returns a copy of an array with all elements of the main diagonal set to a specified scalar value.
Parameters: - a – Rectangular array of two dimensions.
- val – Scalar value to fill the diagonal whose type must be compatible with that of array ‘a’ (i.e. ‘val’ cannot be viewed as an upcast of ‘a’).
- offset – Scalar value Offset of the diagonal from the main diagonal. Can be positive or negative integer.
Returns: An array identical to ‘a’ except that its offset diagonal is filled with scalar ‘val’. The output is unwrapped.
Return type: array
-
theano.tensor.extra_ops.
repeat
(x, repeats, axis=None)¶ Repeat elements of an array.
It returns an array which has the same shape as x, except along the given axis. The axis is used to speficy along which axis to repeat values. By default, use the flattened input array, and return a flat output array.
The number of repetitions for each element is repeat. repeats is broadcasted to fit the length of the given axis.
Parameters: - x – Input data, tensor variable.
- repeats (int, scalar or tensor variable) –
- axis (int, optional) –
See also
tensor.tile()
,()
-
theano.tensor.extra_ops.
squeeze
(x)¶ Remove broadcastable dimensions from the shape of an array.
It returns the input array, but with the broadcastable dimensions removed. This is always x itself or a view into x.
New in version 0.6.
Parameters: x – Input data, tensor variable. Returns: x without its broadcastable dimensions. Return type: object
-
theano.tensor.extra_ops.
to_one_hot
(y, nb_class, dtype=None)¶ Return a matrix where each row correspond to the one hot encoding of each element in y.
Parameters: - y – A vector of integer value between 0 and nb_class - 1.
- nb_class (int) – The number of class in y.
- dtype (data-type) – The dtype of the returned matrix. Default floatX.
Returns: A matrix of shape (y.shape[0], nb_class), where each row
i
is the one hot encoding of the correspondingy[i]
value.Return type: object