8

I would like to print numpy array with indentation for debugging.

Say I have an array a = numpy.array([[1,2,3,4], [5,6,7,8]]), then simple print(a) will give

[[ 63 903 942 952]
 [185 332 511 893]]

Now if I put in \t in print("\t" + str(a)), then I get

    [[ 63 903 942 952]
 [185 332 511 893]]

while I want to have

    [[ 63 903 942 952]
     [185 332 511 893]]

2 Answers 2

6

This should do it :

print('\t' + str(a).replace('\n', '\n\t'))
Sign up to request clarification or add additional context in comments.

Comments

4

Try this:

>>> print("\t" + str(a).replace('\n','\n\t'))
        [[1 2 3 4]
         [5 6 7 8]]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.