如何指定在julia中打印Floats数组的格式? [英] How to specify the format for printing an array of Floats in julia?
本文介绍了如何指定在julia中打印Floats数组的格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要打印的数组或矩阵,但只有三位数的精度.我怎么做.我尝试了以下方法.
I have an array or matrix that I want to print, but only to three digits of precision. How do I do that. I tried the following.
> @printf("%.3f", rand())
0.742
> @printf("%.3f", rand(3))
LoadError: TypeError: non-boolean (Array{Bool,1}) used in boolean context
while loading In[13], in expression starting on line 1
更新:理想情况下,我只想调用printx("{.3f}", rand(m, n))
之类的函数,而不必进一步处理数组或矩阵.
Update: Ideally, I just want to call a function like printx("{.3f}", rand(m, n))
without having to further process my array or matrix.
推荐答案
如何?
julia> print(round.(rand(3); digits=3))
[0.188,0.202,0.237]
这篇关于如何指定在julia中打印Floats数组的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文