Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Decoding NumPy’s Dot Product: A Brief Exploration of Dimensional Wizardry

Member-only storyMario Namtao Shianti LarcherFollowTowards Data Science--ShareAm I the only one who periodically gets confused when dealing with dimensions in NumPy? Today, while reading a Gradio’s documentation page, I came across the following code snippet:Hey, hey, hey! Why does the dot product of an image (W, H, 3) with a filter (3, 3) is legal? I asked ChatGPT to explain it to me, but it started giving me wrong answers (like saying this doesn’t work) or ignoring my question and started answering something else instead. So, there was no other solution than using my brain (plus reading the documentation, sigh).If you are also a little confuse by the code above, continue reading.From the NumPy dot product documentation (with minor modifications):If a.shape = (I, J, C) and b.shape = (K, C, L), then dot(a, b)[i, j, k, l] = sum(a[i, j, :] * b[k, :, l]). Notice that the last dimension of “a” is equal to the second-to-last dimension of “b”.Or, in code:Output (same result):To determine the shape of a dot product beforehand, follow these steps:Step 1: Consider two arrays, “a” and “b,” with their respective shapes.----Towards Data ScienceI like spaghetti code with 🍅. Currently Head of Computer Vision at Enel Group.Mario Namtao Shianti Larcherintowards Data Science--2Miriam SantosinTowards Data Science--19Dominik PolzerinTowards Data Science--27Mario Namtao Shianti LarcherinTowards Data Science--Mastafa FoufainTowards AI--6Shuai GuoinTowards Data Science--Rohan Muppa--Cornellius Yudha WijayainTowards AI--3Andy McDonaldinTowards Data Science--3Avi Loeb--13HelpStatusWritersBlogCareersPrivacyTermsAboutText to speechTeams



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Decoding NumPy’s Dot Product: A Brief Exploration of Dimensional Wizardry

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×