1
$\begingroup$
dats = Flatten@
   ParallelTable[
    NumberForm[RandomReal[], {3, 5}], {i, -4, 5, 1}, {j, 73}];
 

Then finding the max. value does not work

Max@dats  

Similarly, if I want to find the position of an element

In[345]:= dats[[1]]

0.00089   

The Position is not working too

In[346]:= Position[dats, 0.33900]

Out[346]= {}
$\endgroup$
8
  • $\begingroup$ Look at the TreeForm for a NumberForm object; and try: Max[dats[[All, 1]]] $\endgroup$
    – Syed
    Commented Feb 27, 2022 at 15:02
  • $\begingroup$ For searching: Position[dats[[All, 1]], 0.05001168909146414]` in my case gives: {{20}}. I had to manually copy and paste to get full precision. $\endgroup$
    – Syed
    Commented Feb 27, 2022 at 15:08
  • $\begingroup$ @Syed, but that destroys number form like to keep.. I need the output of data in 0.00000 and when searching use this form only. $\endgroup$
    – MMA13
    Commented Feb 27, 2022 at 15:12
  • $\begingroup$ I tried SetAccuracy and it works now with Max but not for Position $\endgroup$
    – MMA13
    Commented Feb 27, 2022 at 15:17
  • $\begingroup$ The idea (as I understand it so far) is to let Mathematica handle the numbers internally and format these at the end for display/reporting purposes. May I ask why you would like to use such functionality? Searching for an exact real number is not very useful and results in non-portable code. Usually inequality operators are used. $\endgroup$
    – Syed
    Commented Feb 27, 2022 at 15:18

1 Answer 1

3
$\begingroup$

Remember, NumberForm is a wrapper. E.g.,

SeedRandom[314];
dats = Flatten@Table[NumberForm[RandomReal[], {3, 5}], {i, -4, 5, 1}, {j, 73}];
dats[[1]] // FullForm  (* NumberForm[0.9589271300722904`,List[3,5]] *)

So if you want the biggests, you can try MaximalBy[dats, First].

On the other hand, if you round, then things work more how you seem to want.

SeedRandom[314];
dats2 = Flatten@Table[Round[RandomReal[], 0.00001], {i, -4, 5, 1}, {j, 73}];
dats2[[1]] // FullForm  (* 0.9589300000000001` *)
Position[dats2, 0.95893]   (* {{1}} *)
Max[dats2]  (* 0.99967 *)
Position[dats2, 0.99967]  (* {{209}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.