2

This is a very general question to satisfy a curiosity I've had for years. How is it that NumPy can do the operations it does on an array? How does it work?

If I do

import numpy as np
X = np.linspace(1, 10, 30000000)

for i in range(len(X)):
    X[i] = X[i] + 1

the code will finish in 13.214 seconds. And yet NumPy can do this

X = X + 1
# [Finished in 0.707s]

So obviously, NumPy doesn't use simple loops to access each element of the array to perform any given operation. How does a python package, which is itself just python code, access the hardware at such a low level?

I don't have a great understanding of lower level processes, so simple/basic explanations are appreciated.

feedMe
  • 3,431
  • 2
  • 36
  • 61
John Kealy
  • 1,503
  • 1
  • 13
  • 32
  • 2
    The answers here are pretty easy to understand : https://stackoverflow.com/questions/8385602/why-are-numpy-arrays-so-fast – Deepak Saini Dec 26 '18 at 04:21

0 Answers0