linspace and arange¶

In [1]:
import numpy as np
import matplotlib.pyplot as plt
import IPython.display as ipd
In [2]:
## Generate 100 samples, equally spaced, starting at 0 and ending at 1
x = np.arange(100)/99
plt.plot(x)
Out[2]:
[<matplotlib.lines.Line2D at 0x7ff51c88dbb0>]
In [3]:
print(x[0])
print(x[-1])
0.0
1.0
In [4]:
x = np.linspace(0, 1, 100)
plt.plot(x)
print(x[0])
print(x[-1])
0.0
1.0
In [5]:
## Ex) Take 32 equally spaced samples between -np.pi and np.pi
x = np.linspace(-np.pi, np.pi, 32)
plt.stem(x)
Out[5]:
<StemContainer object of 3 artists>
In [ ]: