Reputation: 1671
I have data in a file which looks like this
0.5,0,-21
0.5,0,-21
0.5,0,-19
0.5,0,-20
0.5,0,-20
1,0,-31
1,0,-28
1,0,-31
1,0,-28
1,0,-30
And I want to create a numpy array. I am doing the following to try copy it into an array:
with open ("bot1.csv") as fd:
array = numpy.fromfile(fd, count=-1, dtype=float, sep=",")
But the resulting array is just:
array([ 0.5, 0. , -21. ])
Any idea what I am doing wrong?
Upvotes: 1
Views: 1508
Reputation: 94485
I would suggest that you use numpy.loadtxt(). It is faster than genfromtxt()
—but less flexible, which should not matter in your case:
table = numpy.loadtxt('bot1.csv', delimiter=',')
Side note: it is best to not call you variable array
, as this is also a name used by NumPy: this makes the code less convenient to paste after doing from numpy import *
or from pylab import *
(in a Python shell), because people can expect array
to mean numpy.array()
, and because the variable name shadows NumPy's array()
.
Upvotes: 4