【发布时间】:2026-01-08 03:40:01
【问题描述】:
在将一个 numpy 浮点数组打印到控制台时,我想要一个快速的视觉提示。如何使用颜色来表示积极/消极?
我发现了这种更改控制台颜色的 hacky 方法,但我不确定它对我的情况是否有用:
>>>YELLOW = '\033[93m'
>>>ENDCOLOR = '\033[0m'
>>>print(YELLOW+'hello'+ENDCOLOR)
hello # <-- this is yellow
>>>this is in your regular console color
但是如果你省略了最后一个字符串:
>>>YELLOW = '\033[93m'
>>>ENDCOLOR = '\033[0m'
>>>print(YELLOW+'hello')
hello #<-- it's yellow
>>>this is yellow as well, until you print ENDCOLOR
【问题讨论】:
-
我认为您需要编写一个自定义函数来打印数组元素以及所需的 ANSI 代码。