tensor.extra_ops
– Tensor Extra Ops#
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.
M (integer scalar) – Number of points in the output window. If zero or less, an empty vector is returned.
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.
vector of doubles
Count number of occurrences of each value in an array of integers.
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
.
x – A one dimensional array of non-negative integers
weights – An 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 non-negative. Optional.
versionadded: (..) – 0.6:
Broadcast any number of arrays against each other.
*args – The arrays to broadcast.
Compute the shape resulting from broadcasting arrays.
*arrays (TensorVariable) – The tensor variables, or their shapes (as tuples), for which the broadcast shape is computed.
arrays_are_shapes (bool (Optional)) – Indicates whether or not the arrays
contains shape tuples. If you use this approach, make sure that the broadcastable dimensions are (scalar) constants with the value 1
–or simply the integer 1
.
Broadcast an array to a new shape.
array – The array to broadcast.
shape – The shape of the desired array.
A readonly view on the original array with the given shape. It is typically not contiguous. Furthermore, more than one element of a broadcasted array may refer to a single memory location.
broadcast
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.
condition – One dimensional array of non-zero and zero values corresponding to indices of slices along a selected axis.
x – Input data, tensor variable.
axis – The axis along which to slice.
x
with selected slices.
Concatenate a list of tensors, broadcasting the non-concatenated dimensions to align.
Return the cumulative product of the elements along a given axis
.
This wraps numpy.cumprod
.
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.
New in version 0.7.
Return the cumulative sum of the elements along a given axis
.
This wraps numpy.cumsum
.
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.
New in version 0.7.
Calculate the n
-th order discrete difference along the 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. This is heavily inspired by numpy.diff
.
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.
New in version 0.6.
Returns a copy of an array with all elements of the main diagonal set to a specified scalar value.
New in version 0.6.
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
).
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 two dimensions
if the later have all dimensions are equals.
Returns a copy of an array with all elements of the main diagonal set to a specified scalar value.
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.
An array identical to a
except that its offset diagonal is filled with scalar val
. The output is unwrapped.
array
Return numbers spaced evenly on a log scale (a geometric progression).
This is similar to logspace, but with endpoints specified directly. Each output sample is a constant multiple of the previous.
samples (Returns num evenly spaced) –
[start (calculated over the interval) –
stop]. –
excluded. (The endpoint of the interval can optionally be) –
start (int, float, or TensorVariable) – The starting value of the sequence.
stop (int, float or TensorVariable) – The end value of the sequence, unless endpoint
is set to False. In that case, the sequence consists of all but the last of num + 1
evenly spaced samples, such that stop
is excluded.
num (int) – Number of samples to generate. Must be non-negative.
base (float) – The base of the log space.
endpoint (bool) – Whether to include the endpoint in the range.
dtype (str, optional) – dtype of the output tensor(s). If None, the dtype is inferred from that of the values provided to the start
and end
arguments.
axis (int) – Axis along which to generate samples. Ignored if both start
and end
have dimension 0. By default, axis=0 will insert the samples on a new left-most dimension. To insert samples on a right-most dimension, use axis=-1.
end (int, float or TensorVariable) –
Warning
The “end” parameter is deprecated and will be removed in a future version. Use “stop” instead.
The end value of the sequence, unless endpoint
is set to False. In that case, the sequence consists of all but the last of num + 1
evenly spaced samples, such that end
is excluded.
steps (float, int, or TensorVariable) –
Warning
The “steps” parameter is deprecated and will be removed in a future version. Use “num” instead.
Number of samples to generate. Must be non-negative
samples –
num
evenly-spaced (in log space) values between [start, stop]. The range is inclusive if
endpoint
is True.
Return evenly spaced numbers over a specified interval.
Returns num
evenly spaced samples, calculated over the interval [start
, stop
].
The endpoint of the interval can optionally be excluded.
start (int, float, or TensorVariable) – The starting value of the sequence.
stop (int, float or TensorVariable) – The end value of the sequence, unless endpoint
is set to False. In that case, the sequence consists of all but the last of num + 1
evenly spaced samples, such that stop
is excluded.
num (int) – Number of samples to generate. Must be non-negative.
endpoint (bool) – Whether to include the endpoint in the range.
retstep (bool) – If true, returns both the samples and an array of steps between samples.
dtype (str, optional) – dtype of the output tensor(s). If None, the dtype is inferred from that of the values provided to the start
and end
arguments.
axis (int) – Axis along which to generate samples. Ignored if both start
and end
have dimension 0. By default, axis=0 will insert the samples on a new left-most dimension. To insert samples on a right-most dimension, use axis=-1.
end (int, float or TensorVariable) –
Warning
The “end” parameter is deprecated and will be removed in a future version. Use “stop” instead.
The end value of the sequence, unless endpoint
is set to False. In that case, the sequence consists of all but the last of num + 1
evenly spaced samples, such that end
is excluded.
steps (float, int, or TensorVariable) –
Warning
The “steps” parameter is deprecated and will be removed in a future version. Use “num” instead.
Number of samples to generate. Must be non-negative
samples (TensorVariable) – Tensor containing num
evenly-spaced values between [start, stop]. The range is inclusive if endpoint
is True.
step (TensorVariable) – Tensor containing the spacing between samples. Only returned if retstep
is True.
Return numbers spaced evenly on a log scale.
base ** start
(base to the power of start) and ends with base ** stop
(see endpoint
below).
start (int, float, or TensorVariable) – base ** start
is the starting value of the sequence
stop (int, float or TensorVariable) – base ** stop
is the endpoint of the sequence, unless endopoint
is set to False. In that case, num + 1
values are spaced over the interval in log-space, and the first num
are returned.
num (int, default = 50) – Number of samples to generate.
base (float, default = 10.0) –
log(samples) / log(base)
(or log_base(samples)
is uniform.
endpoint (bool) – Whether to include the endpoint in the range.
dtype (str, optional) – dtype of the output tensor(s). If None, the dtype is inferred from that of the values provided to the start
and stop
arguments.
axis (int) – Axis along which to generate samples. Ignored if both start
and end
have dimension 0. By default, axis=0 will insert the samples on a new left-most dimension. To insert samples on a right-most dimension, use axis=-1.
end (int float or TensorVariable) –
Warning
The “end” parameter is deprecated and will be removed in a future version. Use “stop” instead.
The end value of the sequence, unless endpoint
is set to False. In that case, the sequence consists of all but the last of num + 1
evenly spaced samples, such that end
is excluded.
steps (int or TensorVariable) –
Warning
The “steps” parameter is deprecated and will be removed in a future version. Use “num” instead.
Number of samples to generate. Must be non-negative
samples – Tensor containing num
evenly-spaced (in log-pace) values between [start, stop]. The range is inclusive if endpoint
is True.
Converts a tuple of index arrays into an array of flat indices, applying boundary modes to the multi-index.
multi_index (tuple of PyTensor or NumPy arrays) – A tuple of integer arrays, one array for each dimension.
dims (tuple of ints) – The shape of array into which the indices from multi_index
apply.
mode ({'raise', 'wrap', 'clip'}, optional) – Specifies how out-of-bounds indices are handled. Can specify either one mode or a tuple of modes, one mode per index. * ‘raise’ – raise an error (default) * ‘wrap’ – wrap around * ‘clip’ – clip to the range In ‘clip’ mode, a negative index which would normally wrap will clip to 0 instead.
order ({'C', 'F'}, optional) – Determines whether the multi-index should be viewed as indexing in row-major (C-style) or column-major (Fortran-style) order.
raveled_indices – An array of indices into the flattened version of an array of dimensions dims
.
Repeat elements of a tensor.
See numpy.repeat()
for more information.
a (tensor_like) – Input tensor
repeats (tensor_like) – The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.
axis (int, optional) – The axis along which to repeat values. By default, use the flattened input array, and return a flat output array.
repeated_tensor – Output tensor which as the same shape as a, except along the given axis
Examples
import pytensor.tensor as pt a = pt.arange(4).reshape((2, 2)) out = pt.repeat(a, repeats=[2, 3], axis=0) print(out.eval())
[[0 1] [0 1] [2 3] [2 3] [2 3]]
When axis is None, the array is first flattened and then repeated
import pytensor.tensor as pt a = pt.arange(4).reshape((2, 2)) out = pt.repeat(a, repeats=[2, 3, 0, 1], axis=None) print(out.eval())
New in version 0.6.
Find indices where elements should be inserted to maintain order.
This wraps numpy.searchsorted
. Find the indices into a sorted array x
such that, if the corresponding elements in v
were inserted before the indices, the order of x
would be preserved.
x (1-D tensor (array-like)) – Input array. If sorter
is None
, then it must be sorted in ascending order, otherwise sorter
must be an array of indices which sorts it.
v (tensor (array-like)) – Contains the values to be inserted into x
.
side ({'left', 'right'}, optional.) – If 'left'
(default), the index of the first suitable location found is given. If 'right'
, return the last such index. If there is no suitable index, return either 0 or N (where N is the length of x
).
sorter (1-D tensor of integers (array-like), optional) – Contains indices that sort array x
into ascending order. They are typically the result of argsort.
indices – Array of insertion points with the same shape as v
.
tensor of integers (int64)
Notes
Binary search is used to find the required insertion points.
This Op is working only on CPU currently.
Examples
>>> from pytensor import tensor as pt >>> from pytensor.tensor import extra_ops >>> x = pt.dvector("x") >>> idx = x.searchsorted(3) >>> idx.eval({x: [1, 2, 3, 4, 5]}) array(2) >>> extra_ops.searchsorted([1, 2, 3, 4, 5], 3).eval() array(2) >>> extra_ops.searchsorted([1, 2, 3, 4, 5], 3, side="right").eval() array(3) >>> extra_ops.searchsorted([1, 2, 3, 4, 5], [-10, 10, 2, 3]).eval() array([0, 5, 1, 2])
New in version 0.9.
Remove broadcastable (length 1) 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.
x – Input data, tensor variable.
axis (None or int or tuple of ints, optional) – Selects a subset of broadcastable dimensions to be removed. If a non broadcastable dimension is selected, an error is raised. If axis
is None
, all broadcastable dimensions will be removed.
Notes
1. If an axis is chosen for a dimension that is not known to be broadcastable an error is raised, even if this dimension would be broadcastable when the variable is evaluated. 2. Similarly, if axis
is None
, only dimensions known to be broadcastable will be removed, even if there are more dimensions that happen to be broadcastable when the variable is evaluated.
x
without axis
dimensions.
Find the unique elements of an array.
Returns the sorted unique elements of an array. There are three optional outputs in addition to the unique elements:
the indices of the input array that give the unique values
the indices of the unique array that reconstruct the input array
the number of times each unique value comes up in the input array
Converts a flat index or array of flat indices into a tuple of coordinate arrays.
indices (PyTensor or NumPy array) – An integer array whose elements are indices into the flattened version of an array of dimensions dims
.
dims (tuple of ints) – The shape of the array to use for unraveling indices
.
order ({'C', 'F'}, optional) – Determines whether the indices should be viewed as indexing in row-major (C-style) or column-major (Fortran-style) order.
unraveled_coords – Each array in the tuple has the same shape as the indices
array.
tuple of ndarray
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4