简体   繁体   中英

how to remove the decimal point

I use numpy.loadtxt() to read some numbers (integers) from files, however, when I print it, it displayed by scientific notation. I use suppress=True, in the end , the decimal disappear. But there is still a decimal point. How to remove?

在此处输入图片说明

There is an optional argument of numpy.loadtxt() called dtype which allows you to specify the datatype of the array. If you don't provide any argument, the default is float, which is what you are seeing.

Therefore, you can do something like:

import numpy as np
data = np.loadtxt("filename.txt", dtype=np.int16)

You can convert your numpy type to int before printing.

# Create example data
example = np.random.rand(10, 2)*10

# Print as integer
print(example.astype(int))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM