此代码段不打印任何内容:
import logging
import numpy as np
logging.info(np.eye(4))
# this doesn't work either
logging.info('matrix', np.eye(4))
但它适用于原生
print
:
import logging
print(np.eye(4))
[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]
我认为问题出在您的日志记录级别上。
如果我尝试
logging.warning(np.eye(4))
,我会在我的控制台中得到一个输出。
试试下面的代码:
import logging
import numpy as np
# Fix logging level issue
logging.getLogger().setLevel(logging.INFO)
logging.info(np.eye(4))
输出:
INFO:root:[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]