Skip to content

Commit 98e0934

Browse files
authoredJan 28, 2022
Merge pull request #186 from rsokl/numpy-vectorized
call out numpy overrides math operators
2 parents 6456001 + 2fd3813 commit 98e0934

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
 

‎Python/Module3_IntroducingNumpy/VectorizedOperations.md

+8
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 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)
Failed to load comments.