np.linspace
时间: 2023-10-14 18:26:41 浏览: 78
`numpy` function `linspace` returns evenly spaced numbers over a specified interval. The function takes three arguments: `start`, `stop`, and `num`.
Syntax:
```python
numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)
```
where,
- `start` : scalar or array_like, optional. The starting value of the sequence.
- `stop` : scalar or array_like. The end value of the sequence, unless `endpoint` is set to `False`.
- `num` : int, optional. Number of samples to generate. Default is `50`.
- `endpoint` : bool, optional. If `True`, the `stop` value is included in the sequence. Default is `True`.
- `retstep` : bool, optional. If `True`, return the step size between consecutive elements. Default is `False`.
- `dtype` : dtype, optional. The type of the output array. Default is `None`.
- `axis` : int, optional. The axis in the result to store the samples. Default is `0`.
Returns:
- `samples` : ndarray. An array of evenly spaced numbers over a specified interval.
Example:
```python
import numpy as np
# Return 5 evenly spaced numbers between -2 and 2
samples = np.linspace(-2, 2, 5)
print(samples)
# Output: [-2. -1. -0. 1. 2.]
```
阅读全文