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.