How to store fixed-digit array data in txt in python

There is too much data, and it is omitted for direct printing, so I want to save it in txt to see in detail. When outputting directly at the beginning, the display is as follows. It
Insert picture description here
is not clear at all. Most of the methods on the Internet only teach how to keep four decimal places in output and printing. If you want to save it to four decimal places, you can use the following code

lbph = get_LBPH(circul_2_8, 256, 8, 8, True)
text = 'lbph.txt'
np.savetxt(text, lbph, fmt="%6.4f")

Insert picture description here
problem solved.

By the way, if you want to print out a fixed number of decimals, you can use

lbph = np.round(lbph, 4)

or

np.set_printoptions(precision=3, suppress=True)

Guess you like

Origin blog.csdn.net/qq_45347185/article/details/110713820