ndims

ndims(A) -> Integer

Returns the number of dimensions of A

Examples

  1. Get the number of dimensions of an array:

    julia> arr = [1, 2, 3, 4, 5];
    julia> ndims(arr)
    1

    This example returns 1 since arr is a one-dimensional array.

  2. Check the number of dimensions of a matrix:

    julia> mat = [1 2 3; 4 5 6; 7 8 9];
    julia> ndims(mat)
    2

    It returns 2 as mat is a two-dimensional matrix.

  3. Get the number of dimensions of a multi-dimensional array:
    julia> cube = [1 2 3; 4 5 6; 7 8 9], [10 11 12; 13 14 15; 16 17 18], [19 20 21; 22 23 24; 25 26 27];
    julia> ndims(cube)
    3

    This example returns 3 as cube is a three-dimensional array.

Common mistake example:

julia> str = "Hello, world!";
julia> ndims(str)
ERROR: MethodError: no method matching ndims(::String)

In this example, ndims is called on a string str. However, ndims is not defined for strings. It's important to note that ndims works for arrays and matrices, not for other data types like strings or integers.

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: