Skip to content Skip to sidebar Skip to footer

Numpy Mmap: "valueerror: Size Of Available Data Is Not A Multiple Of Data-type Size."

I'm trying to get data from 'data.txt' into a numpy array and plot it with matplotlib. This is what each line of the data looks like: '1' 11.658870417634 4.8159509459201 with about

Solution 1:

That's a text file, not a binary file. memmap only works if the data is stored as binary (i.e. stored as the array would be stored in memory).

You can convert the file to binary by reading it in, line-by-line, and storing each converted line in a writable memmap.

Solution 2:

You're better off using numpy.genfromtxt or numpy.loadtxt. For example:

datatype=[('index',numpy.int), ('floati',numpy.float32), ('floatq',numpy.float32)]
filename='data.txt'def main():
    data = numpy.genfromtxt(filename, dtype=datatype) 
    ...

Post a Comment for "Numpy Mmap: "valueerror: Size Of Available Data Is Not A Multiple Of Data-type Size.""