I have a list with two sublists of numbers, e.g.

Sigmaf = {{1,2,3},{3,4,5}};

... and I would like to crown each number with ErrorBar to yield:

{{ErrorBar[1], ErrorBar[2], ErrorBar[3]},{ErrorBar[3], ErrorBar[4], ErrorBar[5]}}

I have tried:

MapThread[ErrorBar[#] &, Flatten[Sigmaf]]

... as well as:

MapThread[ErrorBar[#] &, Sigmaf]

... without success. Any tips?

  • 3
    $\begingroup$ Why use ErrorBar instead of Around? If you're using a more recent version of Mathematica, Around is the modern way to achieve this (and is better supported). $\endgroup$ – ktm Jun 26 at 1:02
  • $\begingroup$ "Crown".......? $\endgroup$ – David G. Stork Jun 26 at 17:46

1. Map ErrorBar at level -1:

Map[ErrorBar, Sigmaf, {-1}]
{{ErrorBar[1], ErrorBar[2], ErrorBar[3]}, 
 {ErrorBar[3], ErrorBar[4],  ErrorBar[5]}}

2. ReplaceAll replacing number x with ErrorBar[x]:

Sigmaf /. x_?NumericQ :> ErrorBar[x]
{{ErrorBar[1], ErrorBar[2], ErrorBar[3]}, 
{ErrorBar[3], ErrorBar[4], ErrorBar[5]}}

3. Map ErrorBar on Flattened input list and use Internal`CopyListStructure:

Internal`CopyListStructure[Sigmaf, ErrorBar /@ Flatten[Sigmaf]]
{{ErrorBar[1], ErrorBar[2], ErrorBar[3]}, 
{ErrorBar[3], ErrorBar[4], ErrorBar[5]}}
| improve this answer | |
  • 1
    $\begingroup$ The {-1} is equivalent to {2} for this particular case right? +1, as I wasn't aware of negative levels until today. $\endgroup$ – flinty Jun 25 at 23:56
  • 1
    $\begingroup$ @flinty, thank you for the vote. Yes, {-1} is the same as {2} for this case. {-1} particularly convenient for sublists with different depths. $\endgroup$ – kglr Jun 26 at 0:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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