<jupyter_start><jupyter_text>4.8. Processing large NumPy arrays with memory mapping<jupyter_code>import numpy as np
nrows, ncols = 1000000, 100
f = np.memmap('memmapped.dat', dtype=np.float32,
              mode='w+', shape=(nrows, ncols))
for i in range(ncols):
    f[:, i] = np.random.rand(nrows)
x = f[:, -1]
del f
f = np.memmap('memmapped.dat', dtype=np.float32,
              shape=(nrows, ncols))
np.array_equal(f[:, -1], x)
del f<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16523605150214593, 'fraction_numerical': 0.03862660944206009, 'mean_word_length': 4.021505376344086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '89786', 'license': 'MIT', 'n_tokens_mistral': 195, 'n_tokens_neox': 184, 'n_words': 43, 'path': 'chapter04_optimization/08_memmap.ipynb', 'repo_name': 'tkondoh1022/cookbook-2nd-code', 'size': '466'}