Content-Length: 293330 | pFad | http://github.com/numpy/numpy/pull/28891/files

7E DOC: Add examples to broadcasting documentation for 2D and 3D array cases by yamato1936 · Pull Request #28891 · numpy/numpy · GitHub
Skip to content

DOC: Add examples to broadcasting documentation for 2D and 3D array cases #28891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions doc/source/user/basics.broadcasting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,38 @@ dimensions in the broadcast increases.
than height because of the larger values. In practice, it is important to
normalize the height and weight, often by their standard deviation across the
data set, so that both have equal influence on the distance calculation.

.. rubric:: Additional example: (3,1) and (1,4) broadcasting

The following example shows how a (3,1) array and a (1,4) array are broadcast to a (3,4) shape:

.. code-block:: python

import numpy as np
a = np.arange(3).reshape(3, 1)
b = np.arange(4).reshape(1, 4)
c = a + b
print(c)
# Output:
# [[0 1 2 3]
# [1 2 3 4]
# [2 3 4 5]]
.. rubric:: Additional example: broadcasting between 3D and 2D arrays

This example shows how a (2, 3, 1) array can be broadcast with a (3, 4) array to produce a (2, 3, 4) result.

.. code-block:: python

import numpy as np
a = np.arange(6).reshape(2, 3, 1) # shape: (2, 3, 1)
b = np.arange(12).reshape(3, 4) # shape: (3, 4)
c = a + b # shape: (2, 3, 4)
print(c)
# Output:
# [[[ 0 1 2 3]
# [ 4 5 6 7]
# [ 8 9 10 11]]
#
# [[ 12 13 14 15]
# [ 16 17 18 19]
# [ 20 21 22 23]]]
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/numpy/numpy/pull/28891/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy