<div dir="ltr"><div><div>Hi again,<br><br></div>Third time is the charm!<br><br></div><div>You can do this to mask out the array where the difference is greater than 0.02:<br><br>IPy> diff = abs(E - gE0)*(abs(E - gE0) < 0.02)<br>
IPy> diff<br>Out> <br>array([[ 0. , 0.00178256, 0.00674264, 0. , 0. ,<br> 0. , 0. , 0. , 0. , 0. ],<br> [ 0.00499484, 0.00321228, 0.00174779, 0.0155495 , 0. ,<br>
0. , 0. , 0. , 0. , 0. ],<br> [ 0. , 0. , 0. , 0.01439379, 0. ,<br> 0. , 0. , 0. , 0. , 0. ],<br>
[ 0. , 0. , 0. , 0. , 0. ,<br> 0. , 0. , 0. , 0. , 0. ],<br> [ 0. , 0. , 0. , 0. , 0. ,<br>
0. , 0. , 0. , 0. , 0. ],<br> [ 0. , 0. , 0. , 0. , 0. ,<br> 0. , 0. , 0. , 0. , 0. ],<br>
[ 0. , 0. , 0. , 0. , 0. ,<br> 0. , 0. , 0. , 0. , 0. ],<br> [ 0. , 0. , 0. , 0. , 0. ,<br>
0. , 0. , 0. , 0. , 0. ],<br> [ 0. , 0. , 0. , 0. , 0.00162705,<br> 0. , 0. , 0. , 0. , 0. ],<br>
[ 0. , 0. , 0. , 0. , 0.00335728,<br> 0. , 0. , 0. , 0. , 0. ]])<br><br></div><div>Now, to get the minima that fulfill this criterion, get the minimum from the non-zero values in this diff array: <br>
<br>IPy> min_values = [(-1 if len(d.nonzero()[0]) == 0 else min(d[d.nonzero()[0]])) for d in diff]<br>IPy> min_values<br>Out> <br>[0.0017825594000000001,<br> 0.00174779433,<br> 0.014393789699999996,<br> -1,<br> -1,<br>
-1,<br> -1,<br> -1,<br> 0.0016270488999999971,<br> 0.0033572820000000031]<br><br></div><div>So, the min_values list is filled with -1 if there is difference below 0.2, otherwise it is filled with the minimum difference.<br>
<br></div><div>Hope this helps!<br>Trey<br></div><div><br><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 8, 2014 at 5:31 PM, THƯỜNG Hoàng Đức <span dir="ltr"><<a href="mailto:hoangthuong.hust@gmail.com" target="_blank">hoangthuong.hust@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>HI Trey,<br><br>I wish you may understand. "You are tying to find the minimum of abs(E - gE0) for <span style="color:rgb(255,0,0)">every</span> sub-array in gE0 ". It is not for every sub_array(for diferent location in array). <br>
Firstly it have condition : abs(E - gE0) < 0.02. And after that I am typing to take the closest value E-gE0 == 0 (It also is minimum) therefor maybe some sub_arrays have not value. I am sorry, It is complicate to understand. Hopefully you can help me.<br>
<br>I will show you a simple example:(The main ideal of my problem)<br><br>I have array ar = [1,<span style="color:rgb(0,0,255)">8,9,10</span>,<span style="color:rgb(255,0,0)">100,101,102</span>,<span style="color:rgb(241,194,50)">1000,1001,1002,1003,</span>5000]<br>
<br>I want to take I = [1,8,100,1000,5000] because 1 is alone and non value follow. 8 is minimum of [8,9,10] and 8,9,10 is follow together.....<br> <br></div><div>Thank you - Merci <br></div>Thuong<br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">2014-04-08 18:45 GMT+02:00 Trey Wenger <span dir="ltr"><<a href="mailto:tvw2pu@virginia.edu" target="_blank">tvw2pu@virginia.edu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div><div>Hi again, Thuong.<br><br></div>I think I understand what you are tying to do. You are tying to find the minimum of abs(E - gE0) for every sub-array in gE0. This is what I would do:<br><br>min_indicies = [abs(E - my_gE0).argmin() for my_gE0 in gE0]<br>
<br></div>So, min_indicies[0] is the index of the minimum of abs(E-gE0[0]), min_indicies[1] is the index of the minimum of abs(E - gE0[1]), etc.<br><br></div>Hope this helps,<br>Trey<br><div><div><br></div></div></div><div>
<div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Apr 8, 2014 at 12:20 PM, THƯỜNG Hoàng Đức <span dir="ltr"><<a href="mailto:hoangthuong.hust@gmail.com" target="_blank">hoangthuong.hust@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div><div>thank you Trey, <br><br></div>How can i find the minimum value for different location in the list. Let me show you more detail: (I am sorry, it is long )<br><br>I have: <br>In [15]: E<br>Out[15]: <br>
array([ 1.00000000e-03, 2.78255940e-03, 7.74263683e-03,<br> 2.15443469e-02, 5.99484250e-02, 1.66810054e-01,<br> 4.64158883e-01, 1.29154967e+00, 3.59381366e+00,<br> 1.00000000e+01])<br>
<br>In [16]: gE0<br>Out[16]: <br>array([[ 1.00000000e-03, 1.00000000e-03, 1.00000000e-03,<br> 1.00000000e-03, 1.00000000e-03, 1.00000000e-03,<br> 1.00000000e-03, 1.00000000e-03, 1.00000000e-03,<br>
1.00000000e-03],<br> [ 5.99484250e-03, 5.99484250e-03, 5.99484250e-03,<br> 5.99484250e-03, 5.99484250e-03, 5.99484250e-03,<br> 5.99484250e-03, 5.99484250e-03, 5.99484250e-03,<br>
5.99484250e-03],<br> [ 3.59381366e-02, 3.59381366e-02, 3.59381366e-02,<br> 3.59381366e-02, 3.59381366e-02, 3.59381366e-02,<br> 3.59381366e-02, 3.59381366e-02, 3.59381366e-02,<br>
3.59381366e-02],<br> [ 2.15443469e-01, 2.15443469e-01, 2.15443469e-01,<br> 2.15443469e-01, 2.15443469e-01, 2.15443469e-01,<br> 2.15443469e-01, 2.15443469e-01, 2.15443469e-01,<br>
2.15443469e-01],<br> [ 1.29154967e+00, 1.29154967e+00, 1.29154967e+00,<br> 1.29154967e+00, 1.29154967e+00, 1.29154967e+00,<br> 1.29154967e+00, 1.29154967e+00, 1.29154967e+00,<br>
1.29154967e+00],<br> [ 1.18292276e+00, 1.20239338e+00, 1.26419499e+00,<br> 1.38016526e+00, 1.57688572e+00, 1.91417885e+00,<br> 2.55149610e+00, 4.10977947e+00, 7.74263683e+00,<br>
7.74263683e+00],<br> [ 2.77831168e-01, 2.82126806e-01, 2.95703802e-01,<br> 3.20921794e-01, 3.62928377e-01, 4.32761236e-01,<br> 5.56895376e-01, 8.15796501e-01, 1.61701932e+00,<br>
4.64158883e+01],<br> [ 7.88832931e-02, 8.01002871e-02, 8.39462486e-02,<br> 9.10876310e-02, 1.02977169e-01, 1.22725700e-01,<br> 1.57778342e-01, 2.30672383e-01, 4.54431889e-01,<br>
2.78255940e+02],<br> [ 4.46767553e-02, 4.53659668e-02, 4.75440123e-02,<br> 5.15882797e-02, 5.83213761e-02, 6.95047231e-02,<br> 8.93535809e-02, 1.30626292e-01, 2.57284143e-01,<br>
1.66810054e+03],<br> [ 4.84949885e-02, 4.92431017e-02, 5.16072881e-02,<br> 5.59971873e-02, 6.33057070e-02, 7.54447993e-02,<br> 9.69899542e-02, 1.41789797e-01, 2.79271195e-01,<br>
1.00000000e+04]])<br><br>In [25]: (abs(E - gE0) < 0.02)<br>Out[25]: <br>array([[ <span style="color:rgb(255,0,0)">True, True, True</span>, False, False, False, False, False, False,<br> False],<br> [ <span style="color:rgb(255,0,0)">True, True, True, True, </span>False, False, False, False, False,<br>
False],<br> [False, False, False, <span style="color:rgb(255,0,0)">True</span>, False, False, False, False, False,<br> False],<br> [False, False, False, False, False, False, False, False, False,<br>
False],<br> [False, False, False, False, False, False, False, <span style="color:rgb(255,0,0)">True</span>, False,<br> False],<br> [False, False, False, False, False, False, False, False, False,<br>
False],<br> [False, False, False, False, False, False, False, False, False,<br> False],<br> [False, False, False, False, False, False, False, False, False,<br> False],<br> [False, False, False, False, <span style="color:rgb(255,0,0)">True</span>, False, False, False, False,<br>
False],<br> [False, False, False, False, <span style="color:rgb(255,0,0)">True</span>, False, False, False, False,<br> False]], dtype=bool)<br><br>In [26]: abs(E - gE0)<br>Out[26]: <br>array([[ 0.00000000e+00, <span style="color:rgb(255,0,0)">1.78255940e-03</span>, 6.74263683e-03,<br>
2.05443469e-02, 5.89484250e-02, 1.65810054e-01,<br> 4.63158883e-01, 1.29054967e+00, 3.59281366e+00,<br> 9.99900000e+00],<br> [ 4.99484250e-03, 3.21228310e-03, <span style="color:rgb(255,0,0)">1.74779432e-03</span>,<br>
1.55495044e-02, 5.39535825e-02, 1.60815211e-01,<br> 4.58164041e-01, 1.28555482e+00, 3.58781882e+00,<br> 9.99400516e+00],<br> [ 3.49381366e-02, 3.31555772e-02, 2.81954998e-02,<br>
1.43937897e-02, 2.40102884e-02, 1.30871917e-01,<br> 4.28220747e-01, 1.25561153e+00, 3.55787553e+00,<br> 9.96406186e+00],<br> [ 2.14443469e-01, 2.12660910e-01, 2.07700832e-01,<br>
1.93899122e-01, 1.55495044e-01, 4.86334153e-02,<br> 2.48715414e-01, 1.07610620e+00, 3.37837019e+00,<br> 9.78455653e+00],<br> [ 1.29054967e+00, 1.28876711e+00, 1.28380703e+00,<br>
1.27000532e+00, 1.23160124e+00, 1.12473961e+00,<br> 8.27390782e-01, <span style="color:rgb(255,0,0)">1.33226763e-15</span>, 2.30226400e+00,<br> 8.70845033e+00],<br> [ 1.18192276e+00, 1.19961082e+00, 1.25645235e+00,<br>
1.35862091e+00, 1.51693729e+00, 1.74736880e+00,<br> 2.08733721e+00, 2.81822980e+00, 4.14882316e+00,<br> 2.25736317e+00],<br> [ 2.76831168e-01, 2.79344246e-01, 2.87961166e-01,<br>
2.99377447e-01, 3.02979952e-01, 2.65951182e-01,<br> 9.27364927e-02, 4.75753164e-01, 1.97679434e+00,<br> 3.64158883e+01],<br> [ 7.78832931e-02, 7.73177277e-02, 7.62036117e-02,<br>
6.95432841e-02, 4.30287441e-02, 4.40843535e-02,<br> 3.06380541e-01, 1.06087728e+00, 3.13938177e+00,<br> 2.68255940e+02],<br> [ 4.36767553e-02, 4.25834074e-02, 3.98013755e-02,<br>
3.00439328e-02, <span style="color:rgb(255,0,0)">1.62704897e-03</span>, 9.73053306e-02,<br> 3.74805302e-01, 1.16092337e+00, 3.33652952e+00,<br> 1.65810054e+03],<br> [ 4.74949885e-02, 4.64605423e-02, 4.38646513e-02,<br>
3.44528404e-02, <span style="color:rgb(255,0,0)">3.35728195e-03</span>, 9.13652544e-02,<br> 3.67168929e-01, 1.14975987e+00, 3.31454247e+00,<br> 9.99000000e+03]])<br><br></div>and Finaly: <br>
At the first red line. I would to take the index[2] of value <span style="color:rgb(255,0,0)">1.78255940e-03</span> (minimum)<br>At the second line. <span style="color:rgb(255,0,0)"><span style="color:rgb(0,0,0)">I would to take the index of value </span> 1.74779432e-03 <span style="color:rgb(0,0,0)">(minimum)</span><br>
<span style="color:rgb(0,0,0)">.<br>.<br>.<br><br></span></span></div><div>May you try to help me<br></div><div><br></div><span style="color:rgb(255,0,0)"><span style="color:rgb(0,0,0)">Thuong, </span><br></span></div><div class="gmail_extra">
<br><br><div class="gmail_quote">2014-04-08 16:09 GMT+02:00 Trey Wenger <span dir="ltr"><<a href="mailto:tvw2pu@virginia.edu" target="_blank">tvw2pu@virginia.edu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div>Hi Thuong,<br><br>I would do this<br><br></div>index = abs(gE0[:,0] - ek).argmin()<br><br></div><div>.argmin() returns the index at which the previous argument is smallest. Now, gE0[;,0][index] will be the value of gE0[;,0] closest to ek.<br>
<br></div><div>For example,<br><br>IPy> x = np.array([1.1, 2.3, 4.4])<br>IPy> y = 2.2<br>IPy> index = np.abs(x-y).argmin()<br>IPy> index<br>Out> 1<br>IPy> x[index]<br>Out> 2.3<br>IPy> # this is the value in x closest to y<br>
<br></div><div>Cheers,<br>Trey<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Tue, Apr 8, 2014 at 9:57 AM, THƯỜNG Hoàng Đức <span dir="ltr"><<a href="mailto:hoangthuong.hust@gmail.com" target="_blank">hoangthuong.hust@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><div>Dear AstroPyer,<br><br></div>I have problem with ideals ! <br clear="all">
<div><div><div>Firstly, I have two array. "ek" (one dimension - value in logspace) and "gE0[]" (two dimension - value in logspace). After that I scan value ek in array gE0 to find the equal value, It mean that abs(ek-gE0[:,0]) = 0. Due to the numerical that in logspace, it can not equal zeros(There are some point near the 0), and then I put the error for example err < 0.08 >>>> abs(ek-gE0[:,0]) < 0.08. You can see the value below. The result I would to take is True but it has several value < 0.08 also true, then how can i take smallest if have several True.<br>
<br></div><div><br>In [53]: abs(ek-gE0[:,0]) < 0.08<br>Out[53]: array([False, True, False, False, False, False, True, True, True, True], dtype=bool)<br><br>ek = 0.1<br>In [52]: gE0[:,0]<br>Out[52]: <br>array([ 0.01 , 0.04641589, 0.21544347, 1. , 1.93593016,<br>
0.51306049, 0.15479754, 0.06105322, 0.04410808, 0.04849499])<br><br><div>How can i take only the value: i = 1, value = 0.04641589 and i = 9, value = 0.04410808<br><br><br></div><div>Thankyou very muck<br><br>
</div>
<div>Merci beaucoup,<br><br></div><div>Thuong<br></div><div><br></div><div dir="ltr">================================================<br><font color="#000000">THUONG Hoang Duc <br></font><div><font color="#000000"><font><br>
<span style="font-family:Arial,Helvetica,sans-serif;line-height:15px">Université des Sciences et des Technologies de Hanoi(USTH)</span><br><span style="font-family:Arial,Helvetica,sans-serif;line-height:15px">University of Science and Technology of Hanoi(USTH)<br>
</span><span style="font-family:Tahoma;white-space:pre-wrap">Hanoi University of Science and Technology (HUST)</span><br><br>Email: <a href="mailto:hoangthuong.hust@gmail.com" target="_blank">hoangthuong.hust@gmail.com</a><br>
Tel: <a href="tel:%2B33%2006%2052%2092%2000%2096" value="+33652920096" target="_blank">+33 06 52 92 00 96</a><br>Tel: <a href="tel:%2B84%2001692887738" value="+841692887738" target="_blank">+84 01692887738</a></font><br>
</font><br></div></div>
</div></div></div></div>
<br></div></div>_______________________________________________<br>
AstroPy mailing list<br>
<a href="mailto:AstroPy@scipy.org" target="_blank">AstroPy@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/astropy" target="_blank">http://mail.scipy.org/mailman/listinfo/astropy</a><br>
<br></blockquote></div><span><font color="#888888"><br><br clear="all"><span><font color="#888888"><br>-- <br><div dir="ltr">Trey V. Wenger<div>Department of Astronomy<div>University of Virginia</div></div>
<div><a href="http://www.astro.virginia.edu/~tvw2pu/" target="_blank">http://www.astro.virginia.edu/~tvw2pu/</a></div>
</div>
</font></span></font></span></div><span><font color="#888888">
</font></span></blockquote></div><span><font color="#888888"><br><br clear="all"><br>-- <br><div dir="ltr"><br>================================================<br><font color="#000000">THUONG Hoang Duc <br>
</font><div><font color="#000000"><font><br><span style="font-family:Arial,Helvetica,sans-serif;line-height:15px">Université des Sciences et des Technologies de Hanoi(USTH)</span><br>
<span style="font-family:Arial,Helvetica,sans-serif;line-height:15px">University of Science and Technology of Hanoi(USTH)<br></span><span style="font-family:Tahoma;white-space:pre-wrap">Hanoi University of Science and Technology (HUST)</span><br>
<br>Email: <a href="mailto:hoangthuong.hust@gmail.com" target="_blank">hoangthuong.hust@gmail.com</a><br>Tel: <a href="tel:%2B33%2006%2052%2092%2000%2096" value="+33652920096" target="_blank">+33 06 52 92 00 96</a><br>Tel: <a href="tel:%2B84%2001692887738" value="+841692887738" target="_blank">+84 01692887738</a></font><br>
</font><br></div></div>
</font></span></div>
</blockquote></div><br><br clear="all"><span class="HOEnZb"><font color="#888888"><br>-- <br><div dir="ltr">Trey V. Wenger<div>Department of Astronomy<div>University of Virginia</div></div><div><a href="http://www.astro.virginia.edu/~tvw2pu/" target="_blank">http://www.astro.virginia.edu/~tvw2pu/</a></div>
</div>
</font></span></div><span class="HOEnZb"><font color="#888888">
</font></span></div></div></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><br>-- <br><div dir="ltr"><br>================================================<br><font color="#000000">THUONG Hoang Duc <br>
</font><div><font color="#000000"><font><br>
<span style="font-family:Arial,Helvetica,sans-serif;line-height:15px">Université des Sciences et des Technologies de Hanoi(USTH)</span><br><span style="font-family:Arial,Helvetica,sans-serif;line-height:15px">University of Science and Technology of Hanoi(USTH)<br>
</span><span style="font-family:Tahoma;white-space:pre-wrap">Hanoi University of Science and Technology (HUST)</span><br><br>Email: <a href="mailto:hoangthuong.hust@gmail.com" target="_blank">hoangthuong.hust@gmail.com</a><br>
Tel: <a href="tel:%2B33%2006%2052%2092%2000%2096" value="+33652920096" target="_blank">+33 06 52 92 00 96</a><br>Tel: <a href="tel:%2B84%2001692887738" value="+841692887738" target="_blank">+84 01692887738</a></font><br>
</font><br></div></div>
</font></span></div>
</blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr">Trey V. Wenger<div>Department of Astronomy<div>University of Virginia</div></div><div><a href="http://www.astro.virginia.edu/~tvw2pu/" target="_blank">http://www.astro.virginia.edu/~tvw2pu/</a></div>
</div>
</div>