ndims
ndims(A) -> Integer
Returns the number of dimensions of A
Examples
-
Get the number of dimensions of an array:
julia> arr = [1, 2, 3, 4, 5]; julia> ndims(arr) 1This example returns 1 since
arris a one-dimensional array. -
Check the number of dimensions of a matrix:
julia> mat = [1 2 3; 4 5 6; 7 8 9]; julia> ndims(mat) 2It returns 2 as
matis a two-dimensional matrix. - 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) 3This example returns 3 as
cubeis 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.