Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.1K Views
|
11 Replies
|
0 Total Likes
View groups...
Share
Share this post:

GraphicsGrid with a list, but error shows that is not a list

Posted 3 years ago

Hello, Here are my codes:

z= {{1., 0.164132, -0.0113965, 0.598993, 0.679195, 0.955027, 0.40162, 
0.13018, 0.738997, 0.758081, 0.911602, 0.638988}, {0.164132, 1., 
0.485217, 0.245791, -0.194362, 0.24437, 0.290015, 0.668329, 
0.250812, 0.293622, 0.0316222, -0.117155}, {-0.0113965, 0.485217, 
1., 0.545129, -0.269642, -0.0160867, 0.430706, 0.296677, 0.115731, 
0.109433, -0.100411, -0.360248}, {0.598993, 0.245791, 0.545129, 1., 
0.256783, 0.531268, 0.62919, 0.170259, 0.605565, 0.596599, 0.446782,
0.233051}, {0.679195, -0.194362, -0.269642, 0.256783, 1., 0.475094,
0.209235, -0.141537, 0.379801, 0.406273, 0.695015, 
0.512604}, {0.955027, 0.24437, -0.0160867, 0.531268, 0.475094, 1., 
0.272339, 0.223606, 0.756448, 0.761913, 0.838581, 
0.621532}, {0.40162, 0.290015, 0.430706, 0.62919, 0.209235, 
0.272339, 1., 0.0550312, 0.5739, 0.618186, 0.196132, 
0.36243}, {0.13018, 0.668329, 0.296677, 0.170259, -0.141537, 
0.223606, 0.0550312, 1., 0.171375, 0.233564, 0.0285721, 
0.0222475}, {0.738997, 0.250812, 0.115731, 0.605565, 0.379801, 
0.756448, 0.5739, 0.171375, 1., 0.976395, 0.40106, 
0.785208}, {0.758081, 0.293622, 0.109433, 0.596599, 0.406273, 
0.761913, 0.618186, 0.233564, 0.976395, 1., 0.42898, 
0.773681}, {0.911602, 0.0316222, -0.100411, 0.446782, 0.695015, 
0.838581, 0.196132, 0.0285721, 0.40106, 0.42898, 1., 
0.407937}, {0.638988, -0.117155, -0.360248, 0.233051, 0.512604, 
0.621532, 0.36243, 0.0222475, 0.785208, 0.773681, 0.407937, 1.}};
GraphicsGrid[NumberForm[#, 2] & /@ z]

The error showed:

GraphicsGrid::list: <<1>> is not a list of lists.

What's wrong with it?

Thanks.

POSTED BY: Zhenyu Zeng
11 Replies

Grid expects a list of lists. It gave an error because it found a list of objects of the form NumberForm[...]. You must move NumberForm either one level deeper, or to the very top, outside of Grid:

NumberForm[GraphicsGrid[z], 2]
POSTED BY: Gianluca Gorni
Posted 3 years ago

Hi Glanluca, Is there a book to introduce the difference between these? I found it is a little difficult to imagine of those.

POSTED BY: Zhenyu Zeng

It is an invisible wrapper that is wrapped differently. It looks the same, but it affects evaluation.

POSTED BY: Gianluca Gorni

Try NumberForm[Grid[z], 2]

POSTED BY: Gianluca Gorni
Posted 3 years ago

This is another way. But I may not know what makes the difference even I know there is difference between them. The Mathematica language is too flexible.

POSTED BY: Zhenyu Zeng

They are not the same internally, because the wrapper NumberForm is wrapped differently:

In[62]:= 
NumberForm[{10., 20.}, 2] === {NumberForm[10., 2], NumberForm[20., 2]}

Out[62]= False

The difference becomes visible in FullForm.

POSTED BY: Gianluca Gorni
Posted 3 years ago

So, what is the advantage of NumberForm[#, 2] & /@ z? I can't image the advantage of NumberForm[#, 2] & /@ z

POSTED BY: Zhenyu Zeng

You must map NumberForm at level 2:

Grid[Map[NumberForm[#, 2] &, z, {2}]]
POSTED BY: Gianluca Gorni
Posted 3 years ago

Hi Gianluca, Thanks for your reply. I test the Grid[Map[NumberForm[#, 2] &, z, {2}]] and NumberForm[#, 2] & /@ z. It seems that two results are the same. What's the difference between them?

POSTED BY: Zhenyu Zeng
Posted 3 years ago
ClearAll@f

Compare

z // Map[f]
z // Map[f, #, {2}] &
POSTED BY: Rohit Namjoshi
Posted 3 years ago

Hi Rohit, i always know the difference between /@ with Map[,,2], but when I tested [Map[NumberForm[#, 2] &, z, {2}] and GraphicsGrid[NumberForm[#, 2] & /@ z] I found they looked the same. I have no idea they were so different behind.

POSTED BY: Zhenyu Zeng
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard