我在numpy.savetxt周围使用了一个小包装器来自动生成标题名称并为可读的输出创建某种智能的宽度对齐。一个更准系统的解决方案是在这个答案。
我想知道如何指定宽度并使输出文本与中心对齐,而不是像文档中所示的那样左对齐。
从numpy.savetxt
文档中,我看到了以下信息:
Notes ----- Further explanation of the `fmt` parameter (``%[flag]width[.precision]specifier``):
flags:
``-`` : left justify
``+`` : Forces to preceed result with + or -.
``0`` : Left pad the number with zeros instead of space (see width).
width:
Minimum number of characters to be printed. The value is not truncated
if it has more characters.
文档指向python mini格式规范中更“详尽的资源” ,但那里的信息与对齐信息不兼容。
各种对齐选项的含义如下:
Option Meaning
'<' Forces the field to be left-aligned within the available space (this is the default for most objects).
'>' Forces the field to be right-aligned within the available space (this is the default for numbers).
'=' Forces the padding to be placed after the sign (if any) but before the digits. This is used for printing fields in the form ‘+000000120’. This alignment option is only valid for numeric types.
'^' Forces the field to be centered within the available space.
不兼容是因为 savetxt 不接受'^'
作为有效的格式字符。任何人都可以阐明如何在“numpy.savetxt”中指定格式以使输出居中对齐吗?