size

size(A, [dim...])

Returns a tuple containing the dimensions of A. Optionally you can specify the dimension(s) you want the length of, and get the length of that dimension, or a tuple of the lengths of dimensions you asked for.:

julia> A = rand(2,3,4);

julia> size(A, 2)
3

julia> size(A,3,2)
(4,3)

Examples

  1. Get the dimensions of an array:

    julia> A = rand(2, 3, 4);
    julia> size(A)
    (2, 3, 4)

    This example returns a tuple containing the dimensions of the array A.

  2. Get the length of a specific dimension:

    julia> A = rand(2, 3, 4);
    julia> size(A, 2)
    3

    It returns the length of the second dimension of the array A, which is 3.

  3. Get the lengths of multiple dimensions:
    julia> A = rand(2, 3, 4);
    julia> size(A, 3, 2)
    (4, 3)

    It returns a tuple containing the lengths of the third and second dimensions of the array A, which are 4 and 3, respectively.

Common mistake example:

julia> A = rand(2, 3, 4);
julia> size(A, 4)
ERROR: DimensionError: 4 is out of range for array of size (2, 3, 4)

In this example, the specified dimension is out of range for the given array. It's important to ensure that the dimensions provided are within the valid range of the array.

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: