有没有python类似Matlab格式short的函数或者扩展?
Is there an python function or extension that is is similar to Matlab's format short?
Matlab中short的命令格式使得命令window中的所有打印输出为"Short, fixed-decimal format with 4 digits after the decimal point."
我知道有 np.round,但我想在 python 中使用 Matlab 提供的这个功能,这样我就不必每次都写 round 了。这是为了在打印时更好地了解 arrays/dataframes。
我对在不使用 np.round
的情况下在终端中打印的 numbers/floats 的自动 舍入感兴趣
理想情况下,我还希望能够选择位数 (4)。
谢谢
您可以使用 numpy.set_printoptions
,来自文档:
np.set_printoptions(precision=4)
np.array([1.123456789])
[1.1235]
Matlab中short的命令格式使得命令window中的所有打印输出为"Short, fixed-decimal format with 4 digits after the decimal point."
我知道有 np.round,但我想在 python 中使用 Matlab 提供的这个功能,这样我就不必每次都写 round 了。这是为了在打印时更好地了解 arrays/dataframes。
我对在不使用 np.round
的情况下在终端中打印的 numbers/floats 的自动 舍入感兴趣理想情况下,我还希望能够选择位数 (4)。
谢谢
您可以使用 numpy.set_printoptions
,来自文档:
np.set_printoptions(precision=4)
np.array([1.123456789])
[1.1235]