Welcome! In today's lesson, we'll learn how to use functions with NumPy arrays, a crucial concept for managing large amounts of data. This ability facilitates efficient data processing — a teacher calculating class averages or a business analyst summarising company sales illustrates the practical use of these skills. Are you ready? Let's get started!
Two arrays of the same shape can undergo basic arithmetic operations. The operations are performed element-wise, meaning they're applied to each pair of corresponding elements. Suppose we have two grade arrays of students from two subjects. By adding these arrays, we can calculate the total grades:
The two arrays are added element-wise in this code to calculate the total grades.
NumPy's Universal Functions (also called ufuncs
) perform element-wise operations on arrays, including mathematical functions like sin
, cos
, log
, and sqrt
. Let's look at a use case:
