MCPcopy
hub / github.com/numpy/numpy / linspace

Function linspace

numpy/_core/function_base.py:28–188  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

26
27@array_function_dispatch(_linspace_dispatcher)
28def 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

Callers 15

test_basicMethod · 0.90
test_cornerMethod · 0.90
test_typeMethod · 0.90
test_dtypeMethod · 0.90
test_start_stop_arrayMethod · 0.90
test_complexMethod · 0.90
test_subclassMethod · 0.90
test_array_interfaceMethod · 0.90
test_denormal_numbersMethod · 0.90

Calls 6

reshapeMethod · 0.80
wrapMethod · 0.80
astypeMethod · 0.80
ndimFunction · 0.70
indexMethod · 0.45
anyMethod · 0.45

Tested by 15

test_basicMethod · 0.72
test_cornerMethod · 0.72
test_typeMethod · 0.72
test_dtypeMethod · 0.72
test_start_stop_arrayMethod · 0.72
test_complexMethod · 0.72
test_subclassMethod · 0.72
test_array_interfaceMethod · 0.72
test_denormal_numbersMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…