<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from rtf -->
<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<font face="Times New Roman" size="3"><span style="font-size:12pt;">
<div>Hi,</div>
<div style="margin-top:5pt;margin-bottom:5pt;">In my script, I need to compare big NumPy arrays (2D or 3D), and return a list of all cells with difference bigger than a defined threshold. </div>
<div style="margin-top:5pt;margin-bottom:5pt;">The compare itself can be done easily done with "allclose" function, like that:</div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">Threshold = 0.1</span></font></div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">if (np.allclose(Arr1, Arr2, Threshold, equal_nan=True)):</span></font></div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">    Print('Same')</span></font></div>
<div style="margin-top:5pt;margin-bottom:5pt;">But this compare does not return <b><u>which</u></b> cells are not the same.</div>
<div style="margin-top:5pt;margin-bottom:5pt;"><font face="Calibri" size="2"><span style="font-size:11pt;"> </span></font></div>
<div style="margin-top:5pt;margin-bottom:5pt;">The easiest (yet naive) way to know which cells are not the same is to use a simple for loops code like this one:</div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">def CheckWhichCellsAreNotEqualInArrays(Arr1,Arr2,Threshold):</span></font></div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">   if not Arr1.shape == Arr2.shape:</span></font></div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">       return ['Arrays size not the same']</span></font></div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">   Dimensions = Arr1.shape  </span></font></div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">   Diff = []</span></font></div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">   for i in range(Dimensions [0]):</span></font></div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">       for j in range(Dimensions [1]):</span></font></div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">           if not np.allclose(Arr1[i][j], Arr2[i][j], Threshold, equal_nan=True):</span></font></div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">               Diff.append(',' + str(i) + ',' + str(j) + ',' + str(Arr1[i,j]) + ',' </span></font></div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">               + str(Arr2[i,j]) + ',' + str(Threshold) + ',Fail\n')</span></font></div>
<div><font face="Courier New" size="2" color="#548DD4"><span style="font-size:10pt;">       return Diff</span></font></div>
<div style="margin-top:5pt;margin-bottom:5pt;">(and same for 3D arrays - with 1 more for loop)</div>
<div style="margin-top:5pt;margin-bottom:5pt;">This way is very slow when the Arrays are big and full of none-equal cells.</div>
<div style="margin-top:5pt;margin-bottom:5pt;"><font face="Calibri" size="2"><span style="font-size:11pt;"> </span></font></div>
<div style="margin-top:5pt;margin-bottom:5pt;">Is there a fast straight forward way in case they are not the same - to get a list of the uneven cells? maybe some built-in function in the NumPy itself?</div>
<div style="margin-top:5pt;margin-bottom:5pt;">Thanks!</div>
<div style="margin-top:5pt;margin-bottom:5pt;">Nissim</div>
<div><font face="Calibri" size="2"><span style="font-size:11pt;"> </span></font></div>
<div><font face="Calibri" size="2"><span style="font-size:11pt;"> </span></font></div>
</span></font>
</body>
</html>