[Numpy-discussion] Numpy Overhead
Nathaniel Smith
njs at pobox.com
Tue Feb 28 23:15:20 EST 2017
On Feb 28, 2017 2:57 PM, "Sebastian K" <sebastiankaster at googlemail.com>
wrote:
Yes it is true the execution time is much faster with the numpy function.
The Code for numpy version:
def createMatrix(n):
Matrix = np.empty(shape=(n,n), dtype='float64')
for x in range(n):
for y in range(n):
Matrix[x, y] = 0.1 + ((x*y)%1000)/1000.0
return Matrix
if __name__ == '__main__':
n = getDimension()
if n > 0:
A = createMatrix(n)
B = createMatrix(n)
C = np.empty(shape=(n,n), dtype='float64')
C = np.dot(A,B)
#print(C)
In the pure python version I am just implementing the multiplication with
three for-loops.
Measured data with libmemusage:
dimension of matrix: 100x100
heap peak pure python3: 1060565
heap peakt numpy function: 4917180
4 megabytes is less than the memory needed just to load numpy :-). Try a
1000x1000 array (or even bigger), and I think you'll see more reasonable
results.
-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20170228/c8736e5d/attachment.html>
More information about the NumPy-Discussion
mailing list