Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot print numpy arrays with logging module

This snippet doesn’t print anything:

import logging
import numpy as np

logging.info(np.eye(4))

# this doesn't work either
logging.info('matrix', np.eye(4))

But it works fine with native print:

import logging

print(np.eye(4))
[[1. 0. 0. 0.]
 [0. 1. 0. 0.]
 [0. 0. 1. 0.]
 [0. 0. 0. 1.]]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think the issue is with your logging level.

If I try logging.warning(np.eye(4)), I get an output in my console.

Try the following code:

import logging
import numpy as np

# Fix logging level issue
logging.getLogger().setLevel(logging.INFO)

logging.info(np.eye(4))

Output:

INFO:root:[[1. 0. 0. 0.]
 [0. 1. 0. 0.]
 [0. 0. 1. 0.]
 [0. 0. 0. 1.]]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading