memoryview.ndim

ndim An integer indicating how many dimensions of a multi-dimensional array the memory represents.

memoryview.nbytes

nbytes nbytes == product(shape) * itemsize == len(m.tobytes()). This is the amount of space in bytes that the array would use in a contiguous representation. It is not necessarily equal to len(m): >>> import array >>> a = array.array('i', [1,2,3,4,5]) >>> m = memoryview(a) >>> len(m) 5 >>> m.nbytes 20 >>> y = m[::2] >>> len(y) 3 >>> y.nbytes 12 >>> len(y.tobytes()) 12 Multi-dimensional arrays: >>> impo

memoryview.itemsize

itemsize The size in bytes of each element of the memoryview: >>> import array, struct >>> m = memoryview(array.array('H', [32000, 32001, 32002])) >>> m.itemsize 2 >>> m[0] 32000 >>> struct.calcsize('H') == m.itemsize True

memoryview.hex()

hex() Return a string object containing two hexadecimal digits for each byte in the buffer. >>> m = memoryview(b"abc") >>> m.hex() '616263' New in version 3.5.

memoryview.f_contiguous

f_contiguous A bool indicating whether the memory is Fortran contiguous. New in version 3.3.

memoryview.format

format A string containing the format (in struct module style) for each element in the view. A memoryview can be created from exporters with arbitrary format strings, but some methods (e.g. tolist()) are restricted to native single element formats. Changed in version 3.3: format 'B' is now handled according to the struct module syntax. This means that memoryview(b'abc')[0] == b'abc'[0] == 97.

memoryview.c_contiguous

c_contiguous A bool indicating whether the memory is C-contiguous. New in version 3.3.

memoryview.contiguous

contiguous A bool indicating whether the memory is contiguous. New in version 3.3.

memoryview.cast()

cast(format[, shape]) Cast a memoryview to a new format or shape. shape defaults to [byte_length//new_itemsize], which means that the result view will be one-dimensional. The return value is a new memoryview, but the buffer itself is not copied. Supported casts are 1D -> C-contiguous and C-contiguous -> 1D. The destination format is restricted to a single element native format in struct syntax. One of the formats must be a byte format (‘B’, ‘b’ or ‘c’). The byte length of the result mu

memoryview()

memoryview(obj) Return a “memory view” object created from the given argument. See Memory Views for more information.