Change format for data imported from file in Python -
my data file tab separated , looks this:
196 242 3 881250949 186 302 3 891717742 22 377 1 878887116 244 51 2 880606923 166 346 1 886397596 298 474 4 884182806 115 265 2 881171488 253 465 5 891628467 305 451 3 886324817 ... ... .. .........
i imported them in python using numpy
, here script:
from numpy import loadtxt np_data = loadtxt('u.data', delimiter='\t', skiprows=0) print(np_data)
i want print see result, gives me different format:
[[ 1.96000000e+02 2.42000000e+02 3.00000000e+00 8.81250949e+08] [ 1.86000000e+02 3.02000000e+02 3.00000000e+00 8.91717742e+08] [ 2.20000000e+01 3.77000000e+02 1.00000000e+00 8.78887116e+08] ..., [ 2.76000000e+02 1.09000000e+03 1.00000000e+00 8.74795795e+08] [ 1.30000000e+01 2.25000000e+02 2.00000000e+00 8.82399156e+08] [ 1.20000000e+01 2.03000000e+02 3.00000000e+00 8.79959583e+08]]
there point .
in every number in print(np_data)
. how format them original data file?
i've solved this, turn out miss dtype
argument , script should this:
from numpy import loadtxt np_data = loadtxt('u.data',dtype=int ,delimiter='\t', skiprows=0) print(np_data)
and done
Comments
Post a Comment