Numpy中的ndarray
是一种新形式的Python内建类型。所以,它能够在须要时被继承。ndarray造成了许多有用类的基础。
np.memmap就是其中一种,它是内存映射文件。本质上就是使用C语言中的fseek随机访问文件的任何一个位置执行读写操做。当一个特别大的数组没法常驻内存时,np.memmap很是有用。html
参数类型:python
memmap默认的文件打开方式是r+。数组
import numpy as np a = np.random.randint(0, 10, (3, 4), dtype=np.int32) print(a) a.tofile("haha.bin") b = np.memmap("haha.bin", dtype=np.int32, shape=(3, 4)) print(b) b[0, 0] = 100 del b # 关闭文件,自动调用数组的finalize函数 b = np.memmap("haha.bin", dtype=np.int32, shape=(3, 4)) print(b)
输出为:dom
[[7 7 7 3] [9 3 7 9] [0 7 8 8]] [[7 7 7 3] [9 3 7 9] [0 7 8 8]] [[100 7 7 3] [ 9 3 7 9] [ 0 7 8 8]]
https://docs.scipy.org/doc/numpy/reference/arrays.classes.html函数