Skip to content Skip to sidebar Skip to footer

Why Does Outputing Numpy.dot To Memmap Does Not Work?

If I do: a = np.ones((10,1)) b = np.ones((10,1)) c = np.memmap('zeros.mat', dtype=np.float64, mode='w+', shape=(10,10), order='C') a.dot(b.T, out=c) I am getting: ValueError: ou

Solution 1:

It doesn't just have to match the dtype; it also has to have the right type, as in type(c). c is a numpy.memmap instance, not a numpy.ndarray, so that check fails.

As recommended in the numpy.memmap docs, you could instead use mmap.mmap to map the file and create a numpy.ndarray backed by the mmap as its buffer. You can look at the numpy.memmap implementation to see what might be involved in doing that.

Solution 2:

From RKI's comment, use of numpy.asarray works directly, e.g.:

a = np.ones((10,1))
b = np.ones((10,1))

c_memmap = np.memmap('zeros.mat', dtype=np.float64, mode='w+', shape=(10,10), order='C')
c = numpy.asarray(c_memmap)

a.dot(b.T, out=c)

c_memmap.flush()
#etc.

Post a Comment for "Why Does Outputing Numpy.dot To Memmap Does Not Work?"