CS 472 Module 2: Simple Numpy Tunes Part 1

Module content developed by Professor Tralie. Module engine developed by Professor Tralie and Professor Mongan.


Please watch the video below, and click the Next button to continue when you're finished

Linspace

linspace and arange

In [15]:
import numpy as np
import matplotlib.pyplot as plt
import IPython.display as ipd
In [10]:
## Generate 100 samples, equally spaced, starting at 0 and ending at 1
x = np.arange(100)/99
plt.plot(x)
Out[10]:
[<matplotlib.lines.Line2D at 0x23509506c50>]
In [11]:
print(x[0])
print(x[-1])
0.0
1.0
In [13]:
x = np.linspace(0, 1, 100)
plt.plot(x)
print(x[0])
print(x[-1])
0.0
1.0
In [14]:
## Ex) Take 32 equally spaced samples between -np.pi and np.pi
x = np.linspace(-np.pi, np.pi, 32)
plt.stem(x)
C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:3: UserWarning: In Matplotlib 3.3 individual lines on a stem plot will be added as a LineCollection instead of individual lines. This significantly improves the performance of a stem plot. To remove this warning and switch to the new behaviour, set the "use_line_collection" keyword argument to True.
  This is separate from the ipykernel package so we can avoid doing imports until
Out[14]:
<StemContainer object of 3 artists>
In [ ]: