memoryview的完整描述可以查看here :
Create a
memoryview
that references obj. obj must support the buffer protocol. Built-in objects that support the buffer protocol includebytes
andbytearray
.A
memoryview
has the notion of an element, which is the atomic memory unit handled by the originating object obj. For many simple types such asbytes
andbytearray
, an element is a single byte, but other types such asarray.array
may have bigger elements.
最佳答案
内存 View 本质上是 Python 本身中的一个通用 NumPy 数组结构(没有数学)。它允许您在数据结构(如 PIL 图像、SQLlite 数据库、NumPy 数组等)之间共享内存,而无需先复制。这对于大型数据集非常重要。
有了它,您可以将内存映射到一个非常大的文件,对该文件进行切片并对该文件进行计算(如果您使用 NumPy 则最简单)。
关于python - 什么时候应该使用内存 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4845418/