MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

TableForm and NumberForm

  • To: mathgroup at
  • Subject: [mg34744] TableForm and NumberForm
  • From: "David Park" <djmp at>
  • Date: Tue, 4 Jun 2002 03:42:00 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

I've renamed this thread because it is a separate subject, probably
interesting to a number of people.

What is the interaction between NumberForm and TableForm? It seems like I've
butted my head against this problem a number of times.

In the following, NumberForm produces an array with the desired number
format. If you look at FullForm, the whole array is wrapped in NumberForm.
But when the TableForm statement is evaluated, the NumberForm is thrown
away. It is as if TableForm was Applied. Or else NumberForm is stripped
away. We revert to the default 6 place display.

tbl = Table[Random[], {3}, {4}];
NumberForm[tbl, {12, 11}]

In the following NumberForm is mapped onto the individual array elements.
The array displays with the desired number format. Now, when we use
TableForm, the number format is preserved and we obtain the desired display.
So, why is NumberForm stripped away in the first case and not in this case.

tb2 = Table[Random[], {3}, {4}];
Map[NumberForm[#, {12, 11}] &, %, {-1}]

If we map NumberForm onto each row in the array, then TableForm acts as if
it had a list of three elements, each element with the Head NumberForm. This
displays as a column of three lists.

tb3 = Table[Random[], {3}, {4}];
Map[NumberForm[#, {12, 11}] &, %, {1}]

So why didn't the first case act as a TableForm of a single element? If we
rewrite the first case this way, it does. We obtain a single element in our
table, namely the entire array wrapped in NumberForm.

tb4 = Table[Random[], {3}, {4}];
TableForm[NumberForm[tb4, {12, 11}]]

In any case, it appears that when using TableForm and NumberForm, the surest
procedure is to map NumberForm onto the individual array elements.

David Park
djmp at

> From: DrBob [mailto:majort at]
To: mathgroup at
> Bob,
> Thanks!  My first attempt was evidently too simplistic.  But look at the
> difference between these two output forms:
> tbl = Table[Random[], {3}, {4}]
> NumberForm[TableForm[tbl], {12, 11}]
> TableForm[NumberForm[tbl, {12, 11}]]
> Is that what you'd expect?  (I'm seeing brackets, etc. displayed in the
> second version.)
> Bobby
> From: BobHanlon at [mailto:BobHanlon at]
To: mathgroup at
> In a message dated 6/3/02 3:12:04 AM, majort at writes:
> >ODDLY ENOUGH, when I tried to use NumberForm within TableForm, the
> >result didn't display as a table, so I don't know how to show different
> >columns of the table at different display precisions.
> >
> >QUESTION: Does anybody know how to do that?
> TableForm[
>   Map[
>     NumberForm[#, {4, 3},
>         NumberPadding->{"", "0"}]&,
>     Table[Random[], {3}, {4}], {2}],
>   TableHeadings->{Automatic, Automatic}]
> TableForm[
>   Table[
>     NumberForm[
>       Random[], {5, n},
>       NumberPadding->{"", "0"}],
>     {3}, {n, 4}],
>   TableHeadings->{Automatic, Automatic}]
> Bob Hanlon
> Chantilly, VA  USA

  • Prev by Date: Re: Encapsulated submissions
  • Next by Date: RE: TableForm and NumberForm
  • Previous by thread: Re: Encapsulated submissions
  • Next by thread: RE: TableForm and NumberForm