<div class="text-justify">  <center>[Image Source](https://www.educba.com/numpy-broadcasting/)</center> Today we will look into broadcasting in NumPy. Broadcasting is a powerful feature that allows NumPy to perform arithmetic operations on arrays of different shapes and sizes, without explicitly reshaping them. This is particularly useful when working with arrays of different dimensions but performing similar operations. Let’s look at an example where broadcasting helps us add a scalar to a 2D array. Here’s the code: ``` import numpy as np # Creating a 2D array of size 3x3 array_1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # Adding a scalar (constant) to every element of the array result_array = array_1 + 10 print("Original Array:") print(array_1) print("\nArray After Addition:") print(result_array) ``` <br> In the code above, we created a 3x3 array, and then added a scalar value 10 to each element of the array. Due to broadcasting, NumPy automatically applies the scalar value to each element without needing any loop or explicit reshaping. The output will look like this:  Now let’s see another common use of broadcasting—adding a 1D array to a 2D array. We’ll add a 1D array to each row of the 2D array. ``` # Creating a 1D array array_2 = np.array([1, 2, 3]) # Adding the 1D array to each row of the 2D array broadcasted_result = array_1 + array_2 print("\nArray After Broadcasting Addition:") print(broadcasted_result) ``` <br> In this case, NumPy automatically broadcasts the 1D array across each row of the 2D array, adding the corresponding elements. This is what the output will look like:  As you can see, NumPy handled the broadcasting operation automatically, adding each element of the 1D array to the corresponding row of the 2D array. This makes the process much more efficient than manually looping through the rows and columns. Broadcasting is very powerful because it will save you a lot of time and memory when dealing with arrays of complex shapes and sizes. It's a feature you’ll use often when working with large datasets or mathematical operations in NumPy. </div>
author | leoumesh | ||||||
---|---|---|---|---|---|---|---|
permlink | numpy-broadcasting | ||||||
category | hive-196387 | ||||||
json_metadata | {"app":"peakd/2025.1.3","format":"markdown","tags":["python","programming","code","coding","tutorial","numpy","education","science","stem"],"users":[],"image":["https://images.hive.blog/DQmZu9cTsdvF477PrvtLeeNXHLadCRSoNwEAwaikRp9ebcx/image.png","https://images.hive.blog/DQmQ4ir2KVFBBTnYK7LMsNxzDTBz4Uj3yjqjmy4eK8bH8fC/image.png","https://images.hive.blog/DQmbsQLA337ZM2q8UNicivCmAZLTBsewiM1GTCkan1QLwwQ/image.png"]} | ||||||
created | 2025-02-10 22:41:21 | ||||||
last_update | 2025-02-10 22:41:21 | ||||||
depth | 0 | ||||||
children | 1 | ||||||
last_payout | 2025-02-17 22:41:21 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 1.564 HBD | ||||||
curator_payout_value | 1.601 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 2,415 | ||||||
author_reputation | 212,340,493,251,438 | ||||||
root_title | "NumPy Broadcasting" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 140,703,209 | ||||||
net_rshares | 7,753,402,608,623 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
kevinwong | 0 | 1,861,301,039 | 0.9% | ||
eric-boucher | 0 | 5,157,570,164 | 0.9% | ||
roelandp | 0 | 191,798,660,735 | 7.5% | ||
cloh76 | 0 | 1,261,962,647 | 0.9% | ||
logic | 0 | 24,845,978,574 | 80% | ||
sunshine | 0 | 43,367,818,095 | 7.5% | ||
rmach | 0 | 1,439,684,619 | 7.5% | ||
lemouth | 0 | 463,111,460,479 | 15% | ||
netaterra | 0 | 4,327,652,631 | 0.9% | ||
tfeldman | 0 | 1,690,752,124 | 0.9% | ||
metabs | 0 | 1,649,648,343 | 15% | ||
mcsvi | 0 | 107,392,982,000 | 50% | ||
lk666 | 0 | 700,943,702 | 0.9% | ||
boxcarblue | 0 | 5,703,918,414 | 0.9% | ||
steemcleaners | 0 | 2,087,535,568,647 | 80% | ||
justyy | 0 | 12,584,800,481 | 1.8% | ||
michelle.gent | 0 | 1,120,384,747 | 0.36% | ||
eforucom | 0 | 4,715,122,741 | 1.8% | ||
curie | 0 | 93,971,685,913 | 1.8% | ||
modernzorker | 0 | 824,624,056 | 1.25% | ||
techslut | 0 | 40,098,691,715 | 6% | ||
steemstem | 0 | 276,999,842,728 | 15% | ||
yadamaniart | 0 | 1,476,942,428 | 0.9% | ||
bigtakosensei | 0 | 467,776,710 | 0.45% | ||
walterjay | 0 | 195,737,562,051 | 7.5% | ||
valth | 0 | 1,234,399,092 | 7.5% | ||
metroair | 0 | 8,109,343,730 | 1.8% | ||
driptorchpress | 0 | 703,558,099 | 0.45% | ||
dna-replication | 0 | 538,267,014 | 15% | ||
travelnepal | 0 | 4,161,165,691 | 100% | ||
dhimmel | 0 | 52,534,624,248 | 3.75% | ||
oluwatobiloba | 0 | 1,156,630,964 | 100% | ||
detlev | 0 | 11,199,112,463 | 0.54% | ||
dune69 | 0 | 2,393,680,230 | 1.8% | ||
federacion45 | 0 | 844,362,252 | 0.9% | ||
gamersclassified | 0 | 1,599,659,282 | 0.9% | ||
forykw | 0 | 5,643,750,883 | 0.9% | ||
mobbs | 0 | 48,479,314,518 | 15% | ||
jerrybanfield | 0 | 6,075,894,935 | 1.8% | ||
rt395 | 0 | 1,004,773,891 | 1.5% | ||
bitrocker2020 | 0 | 2,542,529,513 | 0.36% | ||
ohamdache | 0 | 1,156,027,982 | 0.9% | ||
sustainablyyours | 0 | 1,058,560,377 | 7.5% | ||
arunava | 0 | 5,315,686,691 | 0.72% | ||
juancar347 | 0 | 6,406,525,637 | 0.9% | ||
samminator | 0 | 8,568,573,382 | 7.5% | ||
enjar | 0 | 17,800,968,770 | 1.62% | ||
lorenzor | 0 | 1,248,600,045 | 50% | ||
ewkaw | 0 | 659,563,297,441 | 20% | ||
alexander.alexis | 0 | 9,019,310,835 | 15% | ||
jayna | 0 | 2,642,624,180 | 0.36% | ||
techken | 0 | 3,388,356,031 | 3.75% | ||
princessmewmew | 0 | 2,353,033,569 | 0.9% | ||
joeyarnoldvn | 0 | 456,025,936 | 1.47% | ||
gunthertopp | 0 | 18,174,999,731 | 0.36% | ||
pipiczech | 0 | 805,232,075 | 1.8% | ||
empath | 0 | 2,108,684,742 | 1.53% | ||
eturnerx | 0 | 21,052,832,751 | 1.6% | ||
minnowbooster | 0 | 797,625,368,339 | 20% | ||
felt.buzz | 0 | 2,592,656,981 | 0.45% | ||
howo | 0 | 241,576,218,192 | 15% | ||
tsoldovieri | 0 | 1,564,441,809 | 7.5% | ||
neumannsalva | 0 | 1,655,833,159 | 0.9% | ||
stayoutoftherz | 0 | 53,840,929,268 | 0.45% | ||
abigail-dantes | 0 | 5,694,289,771 | 15% | ||
coindevil | 0 | 942,900,338 | 1.44% | ||
zonguin | 0 | 560,854,829 | 3.75% | ||
investingpennies | 0 | 5,040,287,603 | 1.8% | ||
iamphysical | 0 | 12,449,244,290 | 90% | ||
zyx066 | 0 | 1,189,521,203 | 0.54% | ||
revo | 0 | 1,242,037,683 | 1.8% | ||
azulear | 0 | 562,478,601 | 100% | ||
psicoluigi | 0 | 780,842,587 | 50% | ||
rocky1 | 0 | 258,270,099,042 | 0.27% | ||
thelordsharvest | 0 | 591,224,426 | 1.8% | ||
aidefr | 0 | 1,574,270,265 | 7.5% | ||
torico | 0 | 469,494,227 | 0.59% | ||
amphlux | 0 | 623,053,762 | 0.9% | ||
fatman | 0 | 9,192,785,136 | 2% | ||
votehero | 0 | 21,370,983,630 | 4.3% | ||
cryptononymous | 0 | 629,256,809 | 0.9% | ||
msp-makeaminnow | 0 | 21,651,808,411 | 23.9% | ||
sharpshot | 0 | 118,532,144,965 | 40% | ||
meno | 0 | 11,535,933,623 | 0.9% | ||
buttcoins | 0 | 11,574,698,961 | 0.36% | ||
enzor | 0 | 838,764,060 | 15% | ||
bartosz546 | 0 | 2,872,282,424 | 0.9% | ||
dreamm | 0 | 2,839,891,283 | 50% | ||
florian-glechner | 0 | 3,473,908,753 | 0.18% | ||
sunsea | 0 | 2,226,415,558 | 0.9% | ||
bluefinstudios | 0 | 1,503,020,629 | 0.54% | ||
steveconnor | 0 | 1,670,696,490 | 0.9% | ||
dbddv01 | 0 | 536,272,506 | 3.75% | ||
nicole-st | 0 | 458,561,682 | 0.9% | ||
aboutcoolscience | 0 | 4,113,665,172 | 15% | ||
amestyj | 0 | 63,561,105,415 | 100% | ||
kenadis | 0 | 4,012,597,933 | 15% | ||
madridbg | 0 | 3,209,892,074 | 15% | ||
robotics101 | 0 | 4,635,934,348 | 15% | ||
lpv | 0 | 611,691,057 | 1.87% | ||
adelepazani | 0 | 964,295,725 | 0.36% | ||
sco | 0 | 4,324,388,427 | 15% | ||
ennyta | 0 | 913,713,270 | 50% | ||
juecoree | 0 | 979,312,631 | 10.5% | ||
gabrielatravels | 0 | 1,037,944,826 | 0.62% | ||
hetty-rowan | 0 | 1,495,441,956 | 0.9% | ||
ydavgonzalez | 0 | 2,930,927,595 | 10% | ||
intrepidphotos | 0 | 4,037,372,033 | 11.25% | ||
fineartnow | 0 | 1,367,686,729 | 0.9% | ||
oscarina | 0 | 742,949,294 | 10% | ||
aiziqi | 0 | 1,088,083,339 | 5% | ||
steemvault | 0 | 746,457,104 | 1.8% | ||
communitybank | 0 | 1,290,209,256 | 1.8% | ||
bennettitalia | 0 | 665,104,458 | 0.9% | ||
utube | 0 | 1,283,375,690 | 1.8% | ||
ahmedsy | 0 | 509,594,158 | 1.8% | ||
m1alsan | 0 | 743,067,812 | 0.72% | ||
dynamicrypto | 0 | 663,923,284 | 1% | ||
neneandy | 0 | 2,047,693,107 | 1.8% | ||
marc-allaria | 0 | 639,953,280 | 0.9% | ||
sportscontest | 0 | 1,843,329,758 | 1.8% | ||
videosteemit | 0 | 612,329,665 | 1.8% | ||
gribouille | 0 | 678,604,786 | 15% | ||
pandasquad | 0 | 5,099,945,354 | 1.8% | ||
leoumesh | 0 | 829,754,294 | 100% | ||
miguelangel2801 | 0 | 731,739,745 | 50% | ||
mproxima | 0 | 712,697,930 | 0.9% | ||
fantasycrypto | 0 | 617,896,767 | 0.9% | ||
didic | 0 | 589,829,005 | 0.9% | ||
emiliomoron | 0 | 1,349,113,305 | 7.5% | ||
dexterdev | 0 | 584,566,189 | 7.5% | ||
photohunt | 0 | 1,052,426,560 | 1.8% | ||
geopolis | 0 | 947,003,246 | 15% | ||
robertbira | 0 | 1,579,040,337 | 3.75% | ||
alexdory | 0 | 2,666,014,956 | 15% | ||
cyprianj | 0 | 878,468,739 | 1.8% | ||
kieranstone | 0 | 520,982,030 | 0.59% | ||
melvin7 | 0 | 25,961,091,255 | 7.5% | ||
francostem | 0 | 2,014,822,196 | 15% | ||
russellstockley | 0 | 534,889,269 | 0.45% | ||
endopediatria | 0 | 672,547,362 | 20% | ||
putu300 | 0 | 1,333,077,163 | 5% | ||
zipporah | 0 | 898,471,629 | 0.36% | ||
superlotto | 0 | 1,855,106,158 | 1.8% | ||
oadissin | 0 | 1,990,269,571 | 0.9% | ||
jorgebgt | 0 | 8,034,767,534 | 100% | ||
bscrypto | 0 | 5,508,280,439 | 0.9% | ||
tomastonyperez | 0 | 15,798,278,541 | 50% | ||
bil.prag | 0 | 889,713,763 | 0.09% | ||
elvigia | 0 | 10,326,428,450 | 50% | ||
sanderjansenart | 0 | 1,850,109,946 | 0.9% | ||
qberry | 0 | 1,358,695,161 | 0.9% | ||
greddyforce | 0 | 1,375,280,935 | 0.66% | ||
melbourneswest | 0 | 826,472,015 | 0.9% | ||
gadrian | 0 | 114,291,760,395 | 9% | ||
therising | 0 | 32,787,952,376 | 1.8% | ||
cryptocoinkb | 0 | 717,101,658 | 0.9% | ||
cyemela | 0 | 477,113,235 | 0.9% | ||
de-stem | 0 | 8,104,924,153 | 14.85% | ||
serylt | 0 | 650,145,910 | 14.7% | ||
voitaksoutache | 0 | 879,752,067 | 10% | ||
josedelacruz | 0 | 4,684,954,061 | 50% | ||
softa | 0 | 1,260,522,927 | 0.36% | ||
erickyoussif | 0 | 594,451,120 | 100% | ||
deholt | 0 | 825,534,627 | 12.75% | ||
minerthreat | 0 | 1,307,038,993 | 0.9% | ||
nateaguila | 0 | 74,281,957,630 | 5% | ||
temitayo-pelumi | 0 | 1,412,958,177 | 15% | ||
andrick | 0 | 795,895,990 | 50% | ||
doctor-cog-diss | 0 | 13,285,827,753 | 15% | ||
trisolaran | 0 | 471,639,987 | 0.9% | ||
musicvoter2 | 0 | 694,551,001 | 1% | ||
uche-nna | 0 | 1,951,876,269 | 1.44% | ||
citizendog | 0 | 605,141,048 | 1.8% | ||
cheese4ead | 0 | 1,236,213,522 | 0.9% | ||
nattybongo | 0 | 5,591,584,952 | 15% | ||
talentclub | 0 | 1,016,356,926 | 0.9% | ||
bflanagin | 0 | 743,690,964 | 0.9% | ||
armandosodano | 0 | 1,769,061,349 | 0.9% | ||
mariaogliastre | 0 | 19,103,802,213 | 100% | ||
goblinknackers | 0 | 82,257,401,204 | 7% | ||
kylealex | 0 | 4,787,802,207 | 10% | ||
fran.frey | 0 | 3,886,535,617 | 50% | ||
thelittlebank | 0 | 6,281,200,159 | 0.9% | ||
pboulet | 0 | 22,203,917,507 | 12% | ||
stem-espanol | 0 | 2,344,353,424 | 100% | ||
voter003 | 0 | 21,223,112,114 | 7.7% | ||
voter007 | 0 | 159,935,719 | 100% | ||
cliffagreen | 0 | 5,110,348,537 | 10% | ||
aleestra | 0 | 15,101,473,198 | 80% | ||
palasatenea | 0 | 619,187,131 | 0.9% | ||
the.success.club | 0 | 1,186,093,602 | 0.9% | ||
bntcamelo | 0 | 660,679,167 | 100% | ||
sincensura | 0 | 1,032,596,333 | 100% | ||
giulyfarci52 | 0 | 1,586,607,680 | 50% | ||
kristall97 | 0 | 697,812,464 | 100% | ||
followjohngalt | 0 | 1,604,064,840 | 1.8% | ||
miguelbaez | 0 | 548,839,059 | 1.8% | ||
steemcryptosicko | 0 | 3,014,983,752 | 0.36% | ||
multifacetas | 0 | 1,084,673,379 | 0.9% | ||
cakemonster | 0 | 937,182,763 | 1.8% | ||
stem.witness | 0 | 864,224,970 | 15% | ||
samsemilia7 | 0 | 983,696,781 | 39% | ||
vaultec | 0 | 394,348,235,124 | 12% | ||
steemstorage | 0 | 2,281,859,149 | 1.8% | ||
aqua.nano | 0 | 472,725,301 | 100% | ||
crowdwitness | 0 | 2,795,941,174 | 7.5% | ||
hairgistix | 0 | 1,072,681,458 | 0.9% | ||
rem-steem | 0 | 506,089,056 | 0.9% | ||
instagram-models | 0 | 4,524,817,377 | 0.9% | ||
steemean | 0 | 10,037,530,815 | 5% | ||
littlesorceress | 0 | 1,184,464,902 | 1.8% | ||
cryptofiloz | 0 | 2,898,151,998 | 1.8% | ||
dawnoner | 0 | 821,378,652 | 0.18% | ||
epicdice | 0 | 586,889,827 | 0.54% | ||
robibasa | 0 | 30,947,675,775 | 10% | ||
beerlover | 0 | 649,642,185 | 0.54% | ||
qwerrie | 0 | 1,850,678,724 | 0.13% | ||
tggr | 0 | 488,387,569 | 0.9% | ||
tiffin | 0 | 1,831,747,191 | 1.8% | ||
reggaesteem | 0 | 501,518,796 | 5% | ||
tokensink | 0 | 1,125,749,867 | 1.8% | ||
elianaicgomes | 0 | 2,031,402,841 | 5% | ||
steemstem-trig | 0 | 268,804,931 | 15% | ||
baltai | 0 | 2,029,780,339 | 0.9% | ||
therealyme | 0 | 4,359,195,234 | 0.13% | ||
ibt-survival | 0 | 44,954,142,486 | 10% | ||
gloriaolar | 0 | 535,351,695 | 0.54% | ||
hive-199963 | 0 | 2,047,568,652 | 1.8% | ||
monica-ene | 0 | 668,393,694 | 0.9% | ||
hivewatchers | 0 | 2,171,453,088 | 55% | ||
thepeakstudio | 0 | 3,096,525,937 | 100% | ||
stemsocial | 0 | 124,863,201,407 | 15% | ||
holoferncro | 0 | 3,865,365,419 | 10% | ||
the100 | 0 | 1,140,512,293 | 0.9% | ||
hivelist | 0 | 529,433,864 | 0.54% | ||
kiemurainen | 0 | 2,147,212,819 | 0.75% | ||
noelyss | 0 | 2,926,974,290 | 7.5% | ||
kingfadino | 0 | 51,086,603,181 | 50% | ||
altleft | 0 | 5,305,959,235 | 0.01% | ||
omarrojas | 0 | 709,456,663 | 0.9% | ||
evagavilan2 | 0 | 533,794,850 | 0.9% | ||
enrico2gameplays | 0 | 958,837,039 | 100% | ||
meritocracy | 0 | 25,046,970,934 | 0.18% | ||
pepeymeli | 0 | 782,051,105 | 50% | ||
he-index | 0 | 23,417,241,939 | 10% | ||
dcrops | 0 | 8,536,408,055 | 0.9% | ||
hive-129556 | 0 | 2,476,599,004 | 100% | ||
peerfinance | 0 | 47,944,583,965 | 100% | ||
whywhy | 0 | 706,091,050 | 0.5% | ||
yozen | 0 | 2,537,885,070 | 0.9% | ||
cryptosneeze | 0 | 573,359,913 | 0.9% | ||
tawadak24 | 0 | 1,421,970,205 | 0.9% | ||
failingforwards | 0 | 928,796,347 | 0.9% | ||
drricksanchez | 0 | 5,176,420,071 | 0.9% | ||
nfttunz | 0 | 2,951,409,752 | 0.18% | ||
okluvmee | 0 | 1,225,973,808 | 0.9% | ||
atexoras.pub | 0 | 480,450,258 | 0.9% | ||
merit.ahama | 0 | 2,297,230,839 | 0.54% | ||
holovision.cash | 0 | 3,650,659,303 | 100% | ||
holovision.stem | 0 | 59,820,111 | 100% | ||
magnacarta | 0 | 544,483,392 | 0.9% | ||
seinkalar | 0 | 4,859,352,397 | 1.8% | ||
sidalim88 | 0 | 615,643,868 | 0.9% | ||
aries90 | 0 | 14,512,764,987 | 1.8% | ||
blingit | 0 | 1,265,374,616 | 0.9% | ||
yixn | 0 | 6,003,315,823 | 0.9% | ||
newilluminati | 0 | 4,633,142,504 | 0.9% | ||
lichtkunstfoto | 0 | 2,709,568,250 | 1.8% | ||
lukasbachofner | 0 | 1,549,809,339 | 0.9% | ||
belug | 0 | 2,258,174,769 | 0.54% | ||
baboz | 0 | 476,867,023 | 0.45% | ||
hk-curation | 0 | 1,723,888,331 | 1.25% | ||
llunasoul | 0 | 2,888,643,094 | 5% | ||
growandbow | 0 | 56,416,605,935 | 5% | ||
acgalarza | 0 | 2,096,107,929 | 0.54% | ||
inibless | 0 | 1,676,285,043 | 7.5% | ||
callmesmile | 0 | 1,031,830,005 | 0.9% | ||
justfavour | 0 | 1,100,448,530 | 0.9% | ||
jijisaurart | 0 | 725,531,723 | 0.9% | ||
wasined | 0 | 3,431,437,352 | 1.8% | ||
clpacksperiment | 0 | 1,049,597,350 | 0.9% | ||
the-burn | 0 | 508,066,955 | 0.9% | ||
ambicrypto | 0 | 445,822,206 | 1.8% | ||
humbe | 0 | 7,520,414,803 | 2% | ||
dresden.theone | 0 | 343,708,922 | 0.9% | ||
jhymi | 0 | 1,850,162,177 | 0.9% | ||
opticus | 0 | 110,836,216 | 1.8% | ||
rhemagames | 0 | 1,760,174,373 | 0.9% | ||
kryptof | 0 | 6,468,584,478 | 10% | ||
oladamola | 0 | 18,521,699,560 | 20% | ||
bipolar95 | 0 | 1,140,041,053 | 10% |
<div class='text-justify'> <div class='pull-left'> <img src='https://stem.openhive.network/images/stemsocialsupport7.png'> </div> Thanks for your contribution to the <a href='/trending/hive-196387'>STEMsocial community</a>. Feel free to join us on <a href='https://discord.gg/9c7pKVD'>discord</a> to get to know the rest of us! Please consider delegating to the @stemsocial account (85% of the curation rewards are returned). Thanks for including @stemsocial as a beneficiary, which gives you stronger support. <br /> <br /> </div>
author | stemsocial |
---|---|
permlink | re-leoumesh-numpy-broadcasting-20250212t041543379z |
category | hive-196387 |
json_metadata | {"app":"STEMsocial"} |
created | 2025-02-12 04:15:42 |
last_update | 2025-02-12 04:15:42 |
depth | 1 |
children | 0 |
last_payout | 2025-02-19 04:15:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 545 |
author_reputation | 22,927,767,309,334 |
root_title | "NumPy Broadcasting" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 140,732,788 |
net_rshares | 0 |