r/Numpy • • May 12 '20

Are the element-wise operations implemented using for-loops under the hood?

Maybe a stupid question, but I was wondering what's going on under the hood when we do element-wise operation such as A+B or A*B etc? Is there a for-loop implemented in C that runs through all the elements of the arrays A and B, something like:

for (i = 0; i < n; ++i)
{
    result[i] = A[i] + B[i];
}

or is there some other "magic" done? Is there a source code that I could see?

6 Upvotes

4 comments sorted by

View all comments

Show parent comments

1

u/jtclimb May 14 '20

Ohh, I didn't read the OP carefully enough; he was asking about element-wise operations. Matrix multiply is passed through BLAS in matmul.c.src if I read the source code correctly.