Skip to content

Commit a67c6c5

Browse files
committed
call out numpy overrides math operators
1 parent 6456001 commit a67c6c5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Python/Module3_IntroducingNumpy/VectorizedOperations.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ The "modulo" function ("mod" for short), denoted by $\%$, is defined to return t
283283

284284
</div>
285285

286+
<div class="alert alert-info">
287+
288+
**Using Math Operators on NumPy Arrays**:
289+
290+
It is important to note that NumPy arrays know how to "override" the standard mathematical operators so that they also invoke vectorized functions. For example, suppose `arr1` and `arr2` are NumPy arrays; calling `arr1 + arr2` ends up calling `np.add(arr1, arr2)` "under the hood". Thus we can safely use the standard math operators `+ - / * **` between NumPy arrays, and fast vectorized functions will be used for us.
291+
292+
</div>
293+
286294
As indicated in this table, these NumPy functions can be called by invoking the familiar Python math-operators, when used in the context of NumPy arrays.
287295

288296
Here are some other common binary functions:

0 commit comments

Comments
 (0)