From 74483bf3568a1f8c6efbe819578bb2fccdf17a03 Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Wed, 27 Dec 2023 16:24:00 +0100 Subject: [PATCH] Update README.md Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com> --- numpy/broadcasting/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/numpy/broadcasting/README.md b/numpy/broadcasting/README.md index 71d1c5f..6740127 100644 --- a/numpy/broadcasting/README.md +++ b/numpy/broadcasting/README.md @@ -12,6 +12,16 @@ Broadcasting: Automatic adaption of dimensions​ Questions to [David Rotermund](mailto:davrot@uni-bremen.de) +## [General broadcasting rules](https://numpy.org/devdocs/user/basics.broadcasting.html) + +> When operating on two arrays, NumPy compares their shapes element-wise. It starts with the trailing (i.e. rightmost) dimension and works its way left. **Two dimensions are compatible when** +> +> * **they are equal**, or +> * **one of them is 1**. +> +> If these conditions are not met, a ValueError: operands could not be broadcast together exception is thrown, indicating that the arrays have incompatible shapes. +> +> **Input arrays do not need to have the same number of dimensions**. **The resulting array will have the same number of dimensions as the input array with the greatest number of dimensions**, where the size of each dimension is the largest size of the corresponding dimension among the input arrays. Note that missing dimensions are assumed to have size one. ![broadcasting_1.png](broadcasting_1.png)