mygrad.geomspace#
- mygrad.geomspace(start: ArrayLike, stop: ArrayLike, num=50, endpoint=True, dtype=None, axis=0, *, constant: bool | None = None) Tensor [source]#
Return a Tensor with evenly-spaced values in a geometric progression.
Each output sample is a constant multiple of the previous output.
This docstring was adapted from
numpy.geomspace
[1]- Parameters:
- startArrayLike
The starting value of the output.
- stopArrayLike
The ending value of the sequence, inclusive unless endpoint is false.
- numint, optional (default=50)
The number of values to generate. Must be non-negative.
- endpointbool, optional (default=True)
Whether to include the endpoint in the Tensor. Note that if False, the step size changes to accommodate the sequence excluding the endpoint.
- dtypeOptional[DTypeLikeReals]
The data type of the output Tensor, or None to infer from the inputs.
- axisint, optional (default=0)
The axis in the result to store the samples - for array-like start/stop.
- constantOptional[bool]
If
True
, this tensor is a constant, and thus does not facilitate back propagation.Defaults to
False
for float-type data. Defaults toTrue
for integer-type data.Integer-type tensors must be constant.
- Returns:
- Tensor
See also
References
[1]Retrieved from https://numpy.org/doc/stable/reference/generated/numpy.geomspace.html
Examples
>>> import mygrad as mg >>> mg.geomspace(1, 1000, num=4) Tensor([ 1., 10., 100., 1000.]) >>> mg.geomspace(1, 1000, num=3, endpoint=False) Tensor([ 1., 10., 100.]) >>> mg.geomspace(1, 1000, num=4, endpoint=False) Tensor([ 1. , 5.62341325, 31.6227766 , 177.827941 ]) >>> mg.geomspace(1, 256, num=9) Tensor([ 1., 2., 4., 8., 16., 32., 64., 128., 256.])
Note that the above may not produce exact integers:
>>> mg.geomspace(1, 256, num=9, dtype=int) Tensor([ 1, 2, 4, 7, 16, 32, 63, 127, 256]) >>> np.around(mg.geomspace(1, 256, num=9).data).astype(int) array([ 1, 2, 4, 8, 16, 32, 64, 128, 256])
Negative, and decreasing inputs are allowed:
>>> mg.geomspace(1000, 1, num=4) Tensor([ 1000., 100., 10., 1.]) >>> mg.geomspace(-1000, -1, num=4) Tensor([-1000., -100., -10., -1.])