Hello,
I wrote this code, but it was an error:
ArrayPlot[
Map[NumberForm[#, {3, 2}] &, {{1.235, 2.568, 3.951}, {4.555, 5.657,
6.597}}, {2}]]
I can’t imagine where I did wrongly.
Hello,
I wrote this code, but it was an error:
ArrayPlot[
Map[NumberForm[#, {3, 2}] &, {{1.235, 2.568, 3.951}, {4.555, 5.657,
6.597}}, {2}]]
I can’t imagine where I did wrongly.
NumberForm is to be used only for final display, not for calculation. It is a wrapper that ArrayPlot does not know how to unwrap. The same happens for Plot:
Plot[NumberForm[x^2, {3, 2}], {x, -1, 1}]
I wonder if Wolfram has any plans to make this wrapper transparent to calculation in future versions.
From where did you know NumberForm is to be used only for final display, not for calculation?
The documentation for NumberForm states from the outset that NumberForm PRINTS numbers in a certain format. It is a typesetting construct. There is an explicit warning not to use it in calculation, but it is placed at the very end of the last section (Possible Issues):
10*NumberForm[3.14, 2]
MatrixForm is another typesetting construct that prevents calculation. This behaviour is not intuitive, and it is an obstacle to beginners.
Okay. Let me mark this. But I need to keep NumberForm[,{3,2}] to calculate, how should I do?
Here is a way:
NumberForm[3.14, 2] // ToString // ToExpression
There may be more elegant solutions.
To set the precision of numbers in calculation you can consider SetAccuracy.
I just need it to show that precision. Your idea is good!