MCPcopy Create free account
hub / github.com/numpy/numpy / linspace

Function linspace

numpy/core/function_base.py:25–182  ·  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.16.0 Non-scalar `start` and `stop` are now suppo

(start, stop, num=50, endpoint=True, retstep=False, dtype=None,
             axis=0)

Source from the content-addressed store, hash-verified

23
24@array_function_dispatch(_linspace_dispatcher)
25def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None,
26 axis=0):
27 """
28 Return evenly spaced numbers over a specified interval.
29
30 Returns `num` evenly spaced samples, calculated over the
31 interval [`start`, `stop`].
32
33 The endpoint of the interval can optionally be excluded.
34
35 .. versionchanged:: 1.16.0
36 Non-scalar `start` and `stop` are now supported.
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(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
66 .. versionadded:: 1.9.0
67
68 axis : int, optional
69 The axis in the result to store the samples. Relevant only if start
70 or stop are array-like. By default (0), the samples will be along a
71 new axis inserted at the beginning. Use -1 to get an axis at the end.
72
73 .. versionadded:: 1.16.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

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 7

asanyarrayFunction · 0.85
reshapeMethod · 0.80
astypeMethod · 0.80
result_typeFunction · 0.70
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