How to fecth back the samples belongs to gighest entropy value in python

31 views Asked by At

I have a number of samples which are of 500 arrays and the I calculated entropy of that samples, now among the results I need the samples that belong to the highest value produced by the entropy function. How do I fetch them?

samples = [0.08919142 0.20299975 0.27345112 0.08008158 0.17114455 0.18313157]
[0.04224915 0.21561611 0.43386136 0.0442738  0.14967143 0.11432815]
[0.36220791 0.0523787  0.01793364 0.19190067 0.08572935 0.28984973]
[0.10081961 0.19686949 0.24575038 0.08790621 0.1722113  0.19644301]
[0.06516979 0.21291585 0.34325145 0.06270501 0.16454659 0.15141131]
[0.04543053 0.21589061 0.41928421 0.04696213 0.15245707 0.11997546]
[4.66311697e-07 8.46279128e-03 9.90692896e-01 2.33685301e-06
 8.20854607e-04 2.06551252e-05]
[0.25649291 0.10149359 0.0573079  0.16476458 0.13037345 0.28956757]
[0.1405883  0.17286325 0.17146899 0.1121959  0.16901953 0.23386402]
[0.0142856  0.19061965 0.61841351 0.01799348 0.1049923  0.05369546]
[0.01748988 0.19726945 0.58869943 0.02133206 0.11314087 0.0620683 ]
[0.10338218 0.19544177 0.24007383 0.08958368 0.17229998 0.19921856]
[0.0889423  0.20312385 0.27408212 0.07991001 0.17110875 0.18283297]
[0.02141367 0.20328672 0.55685418 0.0252703  0.1215307  0.07164443]
[0.07969692 0.20746248 0.29875164 0.07341995 0.16934345 0.17132556]
[0.07427092 0.20972567 0.31447269 0.06949509 0.16787093 0.1641647 ]
[0.08961913 0.20278591 0.27237169 0.08037575 0.17120467 0.18364286]
[0.06676645 0.2124193  0.33796381 0.0639158  0.16521486 0.15371978]
[0.05386616 0.21545607 0.38409449 0.05387554 0.15859409 0.13411366]
[0.02709865 0.20919091 0.51705339 0.030738   0.1314437  0.08447536]
[0.00588173 0.15803276 0.72598247 0.00847032 0.07354818 0.02808454]
[0.00565705 0.1565705  0.72994295 0.00819312 0.07234943 0.02728695]
[0.02040038 0.20191459 0.56467845 0.02426744 0.11950479 0.06923434]
[0.01245488 0.18584914 0.63738393 0.01602687 0.09964697 0.04863821]
[0.0636222  0.21336829 0.34848149 0.06152317 0.16386137 0.14914349]
[0.07592758 0.20906004 0.30956714 0.07070286 0.16835781 0.16638457]
[0.06809945 0.21198274 0.33363068 0.06492014 0.16574375 0.15562324]
[0.05513579 0.21526866 0.37917886 0.05489092 0.15938055 0.13614522]
[0.03421754 0.21348104 0.47466702 0.03726284 0.14119423 0.09917732]
[0.23996553 0.11084741 0.06759351 0.15878207 0.13718231 0.28562916]
[0.07654163 0.20880747 0.30777294 0.0711484  0.16852977 0.16719979]
[0.093389   0.20085969 0.26306531 0.0829472  0.17166255 0.18807625]
[0.00789641 0.16911497 0.69408704 0.01088865 0.08312141 0.03489152]
[0.0608444  0.21410406 0.35814026 0.059381   0.16253434 0.14499594]
[0.03803838 0.21478655 0.45446985 0.04064031 0.14551004 0.10655487]
[0.1209168  0.185138   0.20479451 0.10063419 0.17171261 0.21680388]
[0.01396856 0.18985156 0.62158143 0.01765624 0.10410701 0.05283521]
[0.55848283 0.00906586 0.00104687 0.1946907  0.02511865 0.21159507]
[0.1692081  0.15450615 0.13219189 0.12756034 0.16228743 0.25424609]
[0.10383987 0.19518428 0.23907507 0.08988156 0.1723107  0.19970853]
[0.06111855 0.21403601 0.35717101 0.05959363 0.16267104 0.14540975]
[0.04467972 0.21585043 0.42265335 0.0463319  0.15182531 0.11865929]
[0.15661992 0.16260258 0.14828454 0.12100762 0.16559466 0.24589068]
[0.06255844 0.21366199 0.35213828 0.06070603 0.16336824 0.14756702]
[0.10843828 0.19255851 0.22928545 0.09284566 0.17233578 0.20453631]
[0.00366166 0.14049391 0.77043837 0.00564531 0.06001191 0.01974885]
[0.28173671 0.08802186 0.04419452 0.17297848 0.11968518 0.29338325]
[0.23688582 0.11263375 0.06967652 0.15761377 0.13842665 0.2847635 ]
[0.04330728 0.21573833 0.42892406 0.04517318 0.15063003 0.11622711]
[0.07517863 0.20936386 0.31177303 0.07015789 0.16814189 0.16538471]
[0.05258797 0.21561554 0.38913687 0.05284692 0.15776862 0.13204409]
[0.03822856 0.21483685 0.45350376 0.04080636 0.14571073 0.10691374]
[0.2710458  0.09360179 0.04939441 0.16963512 0.12424105 0.29208183]
[0.03898263 0.2150237  0.44970745 0.04146291 0.14649409 0.10832921]
[0.12347081 0.18357672 0.20012488 0.10218376 0.17147249 0.21917135]
[0.0265416  0.20872701 0.52068498 0.03021322 0.13056792 0.08326527]
[0.08736766 0.20390017 0.27810968 0.07882162 0.17086885 0.18093202]
[0.02811026 0.20997938 0.51058816 0.03168539 0.13298772 0.08664909]
[0.00914873 0.17461664 0.67679178 0.01234043 0.08823844 0.03886398]
[0.08836272 0.20341122 0.27555665 0.0795102  0.1710232  0.18213602]
[0.09068637 0.20224803 0.2696995  0.0811076  0.17134729 0.18491122]
[0.05509542 0.21527505 0.37933377 0.05485873 0.15935605 0.13608099]
[0.0550043  0.21528937 0.37968375 0.05478605 0.15930061 0.13593592]
[0.03454893 0.21361802 0.47285269 0.03755899 0.1415911  0.09983028]
[0.04019309 0.21528303 0.44372484 0.04251072 0.14771141 0.11057691]
.
.
.
.
.
.
.
[0.02693665 0.20905823 0.51810415 0.03058562 0.13119092 0.08412443]
[0.01439304 0.19087488 0.61735027 0.01810747 0.10528875 0.05398559]
[0.0973241  0.19877606 0.25373246 0.08559119 0.17200904 0.19256715]
[0.14128344 0.1724214  0.1703951  0.11258911 0.16889178 0.23441918]
[0.06910195 0.21164181 0.33041927 0.06567161 0.16612462 0.15704074]
[0.03684165 0.21443955 0.46063123 0.03959103 0.14421759 0.10427895]
[0.13714114 0.17504826 0.17689271 0.11023084 0.16962269 0.23106437]
[0.0234104  0.20567986 0.54213625 0.02722016 0.12527504 0.07627828]
[0.08031679 0.20718939 0.29701728 0.07386274 0.16948994 0.17212385]
[0.00430459 0.14640318 0.75615065 0.00648516 0.06437744 0.02227897]
[0.12267059 0.1840672  0.20157617 0.10169984 0.17155155 0.21843465]

entropy = entropy(samples)
print(entropy)
[10.30418438 10.75938491 10.65158083 10.56111512 10.74889727 10.65211679]

Among the results the highest value is 10.75. now how do I fetch the samples that belong that value?

1

There are 1 answers

0
Marat On BEST ANSWER

Assuming entropy() takes a single list of values,

max_entropy_samples = max(samples, key=entropy)

If samples a 2D numpy array, then it should be:

entropies = np.apply_along_axis(entropy, 1, samples)
max_entropy_sample_idx = np.argmax(entropies)
max_entropy_sample = samples[max_entropy_sample_idx]