Numpy nd-arrays are laid out as contiguous 1-d arrays.
This stack overflow conversation (Copying bytes in Python from Numpy array into string or bytearray) suggests that row indexing of matrices are 'views' into the original array, and that no new array objects allocated in memory when indexing.
However, I'm getting weird results when I look at address locations of individual rows of a numpy matrix. For example,
>> x = numpy.random.rand(2,2)
>> x.data
<read-write buffer for 0x7fdc92a941c0, size 32, offset 0 at 0x7fdc92ad2d30>
>> x[0,].data
<read-write buffer for 0x7fdc92a94a30, size 16, offset 0 at 0x7fdc929e7270>
>> x[1,].data
<read-write buffer for 0x7fdc92a94080, size 16, offset 0 at 0x7fdc929e7030>
Using GDB, I found that the distance between the addresses of x[0,] and x[1,] was 576 bytes and the distance between the addresses of x[0,] and x was 965312 bytes:
>> (gdb) print 0x7fdc929e7030 - 0x7fdc929e7270
$1 = -576
>> (gdb) print 0x7fdc92ad2d30 - 0x7fdc929e7270
$2 = 965312
If no new array objects are created when indexing the rows of matrix x, why are these array views so far apart in memory? Does the distance between array views in memory destroy the cache performance of matrix operations that operate across rows/columns?