-
Book Overview & Buying
-
Table Of Contents
NumPy Essentials
By :
NumPy operations are mostly done element-wise, which requires two arrays in an operation to have the same shape; however, this doesn't mean that NumPy operations can't take two differently shaped arrays (refer to the first example we looked at with scalars). NumPy provides the flexibility to broadcast a smaller-sized array across a larger one. But we can't broadcast the array to just about any shape. It needs to follow certain constrains; we will be covering them in this section. One key idea to keep in mind is that broadcasting involves performing meaningful operations over two differently shaped arrays. However, inappropriate broadcasting might lead to an inefficient use of memory that slows down computation.
The general rule for broadcasting is to determine whether two arrays are compatible with dimensioning. There are two conditions that need to be met:
If the preceding conditions...
Change the font size
Change margin width
Change background colour