<div dir="auto"><div><div class="gmail_extra"><div class="gmail_quote">On Feb 28, 2017 2:57 PM, "Sebastian K" <<a href="mailto:sebastiankaster@googlemail.com">sebastiankaster@googlemail.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Yes it is true the execution time is much faster with the numpy function. <div><br></div><div> The Code for numpy version:</div><div><br></div><div><div>def createMatrix(n):</div><div><span class="m_6806385829120981780gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>Matrix = np.empty(shape=(n,n), dtype='float64')</div><div><span class="m_6806385829120981780gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>for x in range(n):</div><div><span class="m_6806385829120981780gmail-Apple-tab-span" style="white-space:pre-wrap">           </span>for y in range(n):</div><div><span class="m_6806385829120981780gmail-Apple-tab-span" style="white-space:pre-wrap">                   </span>Matrix[x, y] = 0.1 + ((x*y)%1000)/1000.0</div><div><span class="m_6806385829120981780gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>return Matrix </div><div><br></div><div><br></div><div><br></div><div>if __name__ == '__main__':</div><div><span class="m_6806385829120981780gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>n = getDimension()</div><div><span class="m_6806385829120981780gmail-Apple-tab-span" style="white-space:pre-wrap">   </span>if n > 0:</div><div><span class="m_6806385829120981780gmail-Apple-tab-span" style="white-space:pre-wrap">         </span>A = createMatrix(n)</div><div><span class="m_6806385829120981780gmail-Apple-tab-span" style="white-space:pre-wrap">          </span>B = createMatrix(n)</div><div><span class="m_6806385829120981780gmail-Apple-tab-span" style="white-space:pre-wrap">          </span>C = np.empty(shape=(n,n), dtype='float64')</div><div><span class="m_6806385829120981780gmail-Apple-tab-span" style="white-space:pre-wrap">           </span>C = np.dot(A,B)</div><div><br></div><div><span class="m_6806385829120981780gmail-Apple-tab-span" style="white-space:pre-wrap">             </span>#print(C)</div><div><br></div></div><div>In the pure python version I am just implementing the multiplication with three for-loops.</div><div><br></div><div>Measured data with libmemusage:</div><div><div>dimension of matrix: 100x100</div><div>heap peak pure python3: 1060565</div></div><div>heap peakt numpy function: 4917180</div></div></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto">-n</div></div>