Complete the code to create a memory-mapped file named 'data.dat' with shape (100,) and dtype float32.
import numpy as np mmap_array = np.memmap('data.dat', dtype=[1], mode='w+', shape=(100,))
The dtype float32 matches the requirement for the memory-mapped file.
Complete the code to open an existing memory-mapped file 'data.dat' in read-only mode.
mmap_read = np.memmap('data.dat', dtype='float32', mode=[1], shape=(100,))
The mode 'r' opens the file in read-only mode without allowing changes.
Fix the error in the code to correctly create a memory-mapped file with shape (50, 2).
mmap_array = np.memmap('data2.dat', dtype='float64', mode='w+', shape=[1])
The shape must be a tuple, so (50, 2) is correct.
Fill both blanks to create a memory-mapped file 'data3.dat' with dtype int32 and shape (10, 10).
mmap_file = np.memmap('data3.dat', dtype=[1], mode='w+', shape=[2])
The dtype should be int32 and the shape a tuple (10, 10).
Fill all three blanks to open an existing memory-mapped file 'data4.dat' with dtype float64, shape (5, 5), in copy-on-write mode.
mmap_copy = np.memmap('data4.dat', dtype=[1], mode=[2], shape=[3])
The dtype is float64, mode is 'c' for copy-on-write, and shape is (5, 5).