Simple question, but I don't find a helpful answer on the web. I have file create with C++, where I first output a std::size_t k
and then write 2 * x
double
s.
I need to first read the std::size_t k
in python and then iterate in a loop from 0
to k - 1
, read two double x, y
in each iteration and do something with them:
with open('file', 'r') as f:
fig, ax = pyplot.subplots()
k = numpy.fromfile(f, numpy.uint64)[0] # does not work
for j in range(0, k):
# get double x and y somehow
x = numpy.fromfile(f, numpy.double)[0]
y = numpy.fromfile(f, numpy.double)[0]
ax.scatter(x = x, y = y, c = 0)
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
The value I read in k
is 3832614067495317556
, but it should be 4096
. And at the point where I read x
, I immediately get an index out of range exception.