The NumPy system is an open-source numerical extension of Python. This tool can be used to store and manipulate large matrices, which is much more efficient than Python's own nested list (nested list structure) structure, which is also useful for representing matrices (matrix). It is said that NumPy Python is the equivalent of becoming a free, more powerful MATLAB system. The numpy itself is implemented in C.
Turning over the study guide of Packt Publishing House, the first chapter has a comparison of computational efficiency examples to get started.
As a result, in the native 32bit Python run out of the effect of a lot of differences with the book, the first is the 32bit python shaping limit and 64bit a lot of difference:
>>> sys.maxsize2147483647
There is also a problem with datetime timing intensive reading.
Anyway, just try it,
The code is below and the problem is solved StackOverflow
#-*-coding:utf-8-*-ImportSYS fromDatetimeImportdatetimeImportNumPy as NP"""Input format:python vectorsum.py n n:the excepted size for the vector"""defnumpsysum (N): a= Np.arange (N) * * 2b= Np.arange (N) * * 3C= A +breturnCdefpythonsum (N): a=range (n) b=range (n) C= [] forIinchRange (len (a)): A[i]= i * * 2B[i]= i * * 3c.append (A[i]+B[i])returnC size= Int (sys.argv[1]) Start=DateTime.Now () C=pythonsum (size) Delta= DateTime.Now ()-StartPrint "The last 2 elements of the pythonsum are:", c[-2:]Print "Python method Cost Time:", Delta.microsecondsstart=DateTime.Now () C=numpsysum (size) Delta= DateTime.Now ()-StartPrint "The last 2 elements of the numpysum are:", c[-2:]Print "NumPy method Cost Time:", Delta.microseconds
There is no demand for mass processing at the moment. Souvenir ~
Note: The python maxsize that comes with Linux is 9223372036854775807
NumPy Get started with an example vectorsum.py