linspace#

ivy.linspace(start, stop, /, num, *, axis=None, endpoint=True, dtype=None, device=None, out=None)[source]#

Generate a certain number of evenly-spaced values in an interval along a given axis.

See \(arange\) that allows to specify the step size of evenly spaced values in an interval.

Parameters:
  • start (Union[Array, NativeArray, float]) – First entry in the range.

  • stop (Union[Array, NativeArray, float]) – Final entry in the range.

  • num (int) – Number of values to generate.

  • axis (Optional[int], default: None) – Axis along which the operation is performed.

  • endpoint (bool, default: True) – If True, stop is the last sample. Otherwise, it is not included.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – output array data type.

  • device (Optional[Union[Device, NativeDevice]], default: None) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – Tensor of evenly-spaced values.

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Examples

With float input:

>>> x = ivy.linspace(1, 2, 3)
>>> print(x)
ivy.array([1. , 1.5, 2. ])
>>> x = ivy.linspace(1, 2, 4, endpoint=False)
>>> print(x)
ivy.array([1., 1.25, 1.5 , 1.75])
>>> x = ivy.linspace(1, 10, 4, dtype="int32")
>>> print(x)
ivy.array([ 1,  4,  7, 10])
>>> x = ivy.linspace(1, 2, 4, device= "cpu")
>>> print(x)
ivy.array([1., 1.33333337, 1.66666663, 2.])
>>> y = ivy.array([0,0,0,0])
>>> ivy.linspace(1, 2, 4, out= y)
>>> print(y)
ivy.array([1, 1, 1, 2])

With ivy.Array input:

>>> x = ivy.array([1,2])
>>> y = ivy.array([4,5])
>>> z = ivy.linspace(x, y, 4, axis = 0)
>>> print(z)
ivy.array([[1, 2],
           [2, 3],
           [3, 4],
           [4, 5]])
Array.linspace(self, stop, /, num, *, axis=None, endpoint=True, dtype=None, device=None, out=None)[source]#
Return type:

Array

Container.linspace(self, stop, /, num, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, axis=None, endpoint=True, dtype=None, device=None, out=None)[source]#
Return type:

Container