Why is True printed with leading whitespace in numpy array

Viewed 1223

I noticed that in NumPy 1.13.1, when a dtype=np.bool_ array is printed the True values always have a leading whitespace.

>>> import numpy as np
>>> np.asarray([1, 0, 1, 1, 0], dtype=np.bool_)
array([ True, False,  True,  True, False], dtype=bool)
>>> #  ^             ^      ^
... # I would have expected: array([True, False, True, True, False], dtype=bool)
...
>>> str(np.asarray([0, 1, 1, 0], dtype=np.bool_))
'[False  True  True False]'
>>> #   ^     ^
... # Again I would have expected: '[False True True False]'
...
>>> repr(np.asarray([1, 1, 1, 0, 0], dtype=np.bool_))
'array([ True,  True,  True, False, False], dtype=bool)'
>>> #   ^      ^      ^
... # repr() does it too.

Is there any particular reason for formatting it like this?

1 Answers
Related