stride

stride(A, k)

Returns the distance in memory (in number of elements) between adjacent elements in dimension k.

Examples

julia> A = [1 2 3; 4 5 6; 7 8 9];
julia> stride(A, 1)
3

In this example, stride is used to determine the distance in memory (number of elements) between adjacent elements in dimension 1 of the array A. The result is 3, indicating that there are 3 elements between adjacent elements in dimension 1.

julia> B = [10 20 30 40 50 60 70 80 90];
julia> stride(B, 2)
1

Here, stride is used on a 1-dimensional array B to calculate the distance in memory between adjacent elements in dimension 2. Since B has only one dimension, the stride value is 1.

Common mistake example:

julia> C = [100 200 300; 400 500 600];
julia> stride(C, 3)
ERROR: DimensionMismatch("dimension out of range")

In this case, the given dimension k is out of range for the array C. It's essential to provide a valid dimension value within the range of the array's dimensions when using stride.

See Also

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: