From the course: NumPy Essential Training: 1 Foundations of NumPy
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Broadcasting
From the course: NumPy Essential Training: 1 Foundations of NumPy
Broadcasting
- [Instructor] Sometimes we need to apply arithmetic operations on arrays with different shapes. NumPy provides us a way to achieve this with broadcasting. In cases when arrays have unequal sizes, the arithmetic operations are defined if the small array can be effectively expanded to match the larger array by using simple rules. According to the NumPy documentation page, broadcasting is explained as the term broadcasting describes how NumPy treats array with different shapes during arithmetic operations. Subject to certain constraints, the smaller array is broadcast across the larger array so that they have compatible shapes. So how does broadcasting work and when can we apply it? There are simple rules that we can use if we want to apply arithmetic operations onto arrays. For example, what if we want to add them? Then we should first move backwards from the last dimensions of each array, then check if their dimensions are compatible. Then measures are compatible if their axes on…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.