findn

findn(A)

Return a vector of indexes for each dimension giving the locations of the non-zeros in A (determined by A[i]!=0).

Examples

julia> A = [1 0 3; 0 5 0; 7 0 0];
julia> findn(A)
([1, 3], [1, 2, 3], [1, 2])

In this example, the findn function is used to find the indexes of non-zero elements in a 2-dimensional array A. The function returns a tuple of vectors, where each vector corresponds to the indexes along a specific dimension.

  • The first vector [1, 3] represents the row indexes (along the first dimension) where the non-zero elements are located.
  • The second vector [1, 2, 3] represents the column indexes (along the second dimension) of the non-zero elements.
  • The third vector [1, 2] represents the page indexes (along the third dimension) of the non-zero elements.

This function is particularly useful when you need to find the positions of non-zero elements in multi-dimensional arrays.

See Also

find, findfirst, findin, findlast, findmin, findn, findnext, findnz, findprev, rsearch, rsearchindex, searchsorted, searchsortedfirst, searchsortedlast, sort, sort!, sortcols, sortperm, sortperm!,

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: