Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Vectorization and Broadcasting are what make NumPy so fast. Pandas' data structures have similar superpowers!
Example Code
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.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up