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. .. versionchanged:: 1.20.0 Values are rounded towards ``-inf`` instead
(start, stop, num=50, endpoint=True, retstep=False, dtype=None,
axis=0, *, device=None)
| 26 | |
| 27 | @array_function_dispatch(_linspace_dispatcher) |
| 28 | def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, |
| 29 | axis=0, *, device=None): |
| 30 | """ |
| 31 | Return evenly spaced numbers over a specified interval. |
| 32 | |
| 33 | Returns `num` evenly spaced samples, calculated over the |
| 34 | interval [`start`, `stop`]. |
| 35 | |
| 36 | The endpoint of the interval can optionally be excluded. |
| 37 | |
| 38 | .. versionchanged:: 1.20.0 |
| 39 | Values are rounded towards ``-inf`` instead of ``0`` when an |
| 40 | integer ``dtype`` is specified. The old behavior can |
| 41 | still be obtained with ``np.linspace(start, stop, num).astype(np.int_)`` |
| 42 | |
| 43 | Parameters |
| 44 | ---------- |
| 45 | start : array_like |
| 46 | The starting value of the sequence. |
| 47 | stop : array_like |
| 48 | The end value of the sequence, unless `endpoint` is set to False. |
| 49 | In that case, the sequence consists of all but the last of ``num + 1`` |
| 50 | evenly spaced samples, so that `stop` is excluded. Note that the step |
| 51 | size changes when `endpoint` is False. |
| 52 | num : int, optional |
| 53 | Number of samples to generate. Default is 50. Must be non-negative. |
| 54 | endpoint : bool, optional |
| 55 | If True, `stop` is the last sample. Otherwise, it is not included. |
| 56 | Default is True. |
| 57 | retstep : bool, optional |
| 58 | If True, return (`samples`, `step`), where `step` is the spacing |
| 59 | between samples. |
| 60 | dtype : dtype, optional |
| 61 | The type of the output array. If `dtype` is not given, the data type |
| 62 | is inferred from `start` and `stop`. The inferred dtype will never be |
| 63 | an integer; `float` is chosen even if the arguments would produce an |
| 64 | array of integers. |
| 65 | axis : int, optional |
| 66 | The axis in the result to store the samples. Relevant only if start |
| 67 | or stop are array-like. By default (0), the samples will be along a |
| 68 | new axis inserted at the beginning. Use -1 to get an axis at the end. |
| 69 | device : str, optional |
| 70 | The device on which to place the created array. Default: None. |
| 71 | For Array-API interoperability only, so must be ``"cpu"`` if passed. |
| 72 | |
| 73 | .. versionadded:: 2.0.0 |
| 74 | |
| 75 | Returns |
| 76 | ------- |
| 77 | samples : ndarray |
| 78 | There are `num` equally spaced samples in the closed interval |
| 79 | ``[start, stop]`` or the half-open interval ``[start, stop)`` |
| 80 | (depending on whether `endpoint` is True or False). |
| 81 | step : float, optional |
| 82 | Only returned if `retstep` is True |
| 83 | |
| 84 | Size of spacing between samples. |
| 85 |
searching dependent graphs…