Vectorization and Broadcasting Review2:00 with Craig Dennis
Vectorization and Broadcasting are what makes NumPy so fast. Pandas' data structures have similar super powers!
Vectorization in NumPy
Arrays provide a vectorized method named add which removes the need for you to loop through each value to add things together.
np.array([1, 2, 3]) + np.array([4, 5, 6])
array([5, 7, 9])
Broadcasting in NumPy
Scalar values can be broadcasted to values, it's as if there was an equal sized array of all 1's.
conference_counts = np.array([4, 5, 10, 8, 15]) # Broadcast a scalar value conference_counts + 1
array([ 5, 6, 11, 9, 16])
In the next step we'll see how to use vectorization and broadcasting in Pandas.
You need to sign up for Treehouse in order to download course files.Sign up