C-style transformation of non-contiguous to contiguous layout

x = numpy.random.rand(4,3)
.
The shape of the array is therefore 4 × 3 array
(
numpy.shape(x) = (4,3)
). Also any element in the array is associated with its respective,
index (n0, n1).
Then, for a C-style non-contiguous layout with shape, (d0, d1, …, dN−1), the value associated with (n0, n1, …, nN−1) is located in the contiguous layout with index = nC.
If,
![]() |
![]() |
Examples illustrating transformation to contiguous layout in C-style
Eg.1: Location of element in x with index (2, 1)
For a C-style non-contiguous layout x with shape, (d0 = 4, d1 = 3) i.e. (d0, d2−1) ∴ N = 2, the value in (n0 = 2, n1 = 1) of the non-contiguous layout is located in the contiguous layout with index nC given by,
![]() |

Eg.2: Location of element in x with index (3, 1)
For a C-style non-contiguous layout x with shape, (d0 = 4, d1 = 3) the value in (n0 = 3, n1 = 1) of the non-contiguous layout is located in the contiguous layout with index nCgiven by,
![]() |
Notice that to move from the element with index (2, 1) in the array x to the element at (3, 1), three elements within the array must be jumped.
❷Stride in an array
The number of elements that must be jumped to get to the next element (eg. next arrow) is given by the stride.
Stride in N-dimensional C-style array
![]() |
