forked from nipraxis/textbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arange.Rmd
46 lines (37 loc) · 1.01 KB
/
arange.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
---
jupyter:
jupytext:
text_representation:
extension: .Rmd
format_name: rmarkdown
format_version: '1.2'
jupytext_version: 1.11.5
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---
# NumPy arange
[`arange`](https://numpy.org/doc/stable/reference/generated/numpy.arange.html)
in NumPy is very like the Python
[`range`](https://docs.python.org/3/library/stdtypes.html#range)
callable with two important differences:
* `arange` returns an array rather than a `range` instance;
* `arange` arguments can be floating point values.
```{python}
import numpy as np
```
```{python}
np.arange(4, 11, 2)
```
```{python}
np.arange(4, 11, 0.5)
```
Because `arange` returns arrays, you can use NumPy element-wise operations
to multiply by the step size and add a start value. This is one way to create
equally spaced vectors
([`np.linspace`](https://numpy.org/doc/stable/reference/generated/numpy.linspace.html)
is another):
```{python}
np.arange(10) * 0.5 + 4
```