mygrad.linspace#

mygrad.linspace(start: ArrayLike, stop: ArrayLike, num: int = 50, endpoint: bool = True, dtype: DTypeLikeReals | None = None, axis: int = 0, *, constant: bool | None = None) Tensor[source]#

Return a Tensor with evenly-spaced numbers over a specified interval.

Values are generated within [start, stop], with the endpoint optionally excluded.

This docstring was adapted from numpy.linspace [1]

Parameters:
startArrayLike

The starting value of the sequence, inclusive.

stopArrayLike

The ending value of the sequence, inclusive unless include_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 to True for integer-type data.

Integer-type tensors must be constant.

Returns:
Tensor

See also

arange

Similar to linspace, but uses a step size (instead of the number of samples).

logspace

Samples uniformly distributed in log space.

References

Examples

>>> import mygrad as mg
>>> mg.linspace(2.0, 3.0, num=5)
Tensor([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ])
>>> mg.linspace(2.0, 3.0, num=5, endpoint=False)
Tensor([ 2. ,  2.2,  2.4,  2.6,  2.8])