ArrayTools - Maple Help

Home : Support : Online Help : Programming : Low-level Manipulation : Matrices, Vectors, and Arrays : ArrayTools : ArrayTools/SearchArray

ArrayTools

 SearchArray
 return the indices of nonzero elements of the given Array

 Calling Sequence ind := SearchArray(A); ind := SearchArray(A, n); ind := SearchArray(A, location = last); row, col := SearchArray(A, ...); row, col, val := SearchArray(A, ...);

Parameters

 A - the given Array n - (optional) the number of indices returned location = last - (optional) last n numbers will be returned; the default returns the first n numbers ind - the Array stores returned indices val - the Array stores values of found non-zero numbers row - the Array stores the row numbers of returned indices col - the Array stores the column numbers of returned indices

Description

 • The SearchArray(A) function returns a vector of numbers such that each element in the returned vector corresponds to an index of a non-zero entry in A.
 • The SearchArray(A, n) and SearchArray(A, n, location = first) functions return a vector of the first n indices corresponding to non-zero entries in A.
 • The SearchArray(A, n, location = last) function returns a vector of the last n indices corresponding to non-zero entries in A.
 • The row, col := SearchArray(A, ...) function returns two Vectors corresponding to the paired row and column indices for non-zero entries in A.
 • The row, col, val := SearchArray(A, ...) function returns two Vectors corresponding to the paired row and column indices for non-zero entries in A and returns in the third Vector the value of the array A at each of these positions.
 • This function is part of the ArrayTools package, so it can be used in the short form SearchArray(..) only after executing the command with(ArrayTools). However, it can always be accessed through the long form of the command by using ArrayTools[SearchArray](..).

Examples

 > $\mathrm{with}\left(\mathrm{ArrayTools}\right):$
 > $A≔\mathrm{Array}\left(\left[0,3,4,0,6,8,9\right]\right)$
 ${A}{:=}\left[\begin{array}{ccccccc}{0}& {3}& {4}& {0}& {6}& {8}& {9}\end{array}\right]$ (1)
 > $\mathrm{SearchArray}\left(A\right)$
 $\left[\begin{array}{r}{2}\\ {3}\\ {5}\\ {6}\\ {7}\end{array}\right]$ (2)
 > $\mathrm{SearchArray}\left(A,4,\mathrm{location}=\mathrm{first}\right)$
 $\left[\begin{array}{r}{2}\\ {3}\\ {5}\\ {6}\end{array}\right]$ (3)
 > $\mathrm{SearchArray}\left(A,4,\mathrm{location}=\mathrm{last}\right)$
 $\left[\begin{array}{r}{3}\\ {5}\\ {6}\\ {7}\end{array}\right]$ (4)
 > $B≔\mathrm{Array}\left(\left[\left[1,2\right],\left[0,9\right],\left[7,0\right],\left[-6,4\right]\right]\right)$
 ${B}{:=}\left[\begin{array}{rr}{1}& {2}\\ {0}& {9}\\ {7}& {0}\\ {-}{6}& {4}\end{array}\right]$ (5)
 > $\mathrm{row},\mathrm{col}≔\mathrm{SearchArray}\left(B\right)$
 ${\mathrm{row}}{,}{\mathrm{col}}{:=}\left[\begin{array}{r}{1}\\ {3}\\ {4}\\ {1}\\ {2}\\ {4}\end{array}\right]{,}\left[\begin{array}{r}{1}\\ {1}\\ {1}\\ {2}\\ {2}\\ {2}\end{array}\right]$ (6)
 > $\mathrm{row},\mathrm{col},\mathrm{val}≔\mathrm{SearchArray}\left(B\right)$
 ${\mathrm{row}}{,}{\mathrm{col}}{,}{\mathrm{val}}{:=}\left[\begin{array}{r}{1}\\ {3}\\ {4}\\ {1}\\ {2}\\ {4}\end{array}\right]{,}\left[\begin{array}{r}{1}\\ {1}\\ {1}\\ {2}\\ {2}\\ {2}\end{array}\right]{,}\left[\begin{array}{r}{1}\\ {7}\\ {-}{6}\\ {2}\\ {9}\\ {4}\end{array}\right]$ (7)
 > $\mathrm{row},\mathrm{col},\mathrm{val}≔\mathrm{SearchArray}\left(B,4\right)$
 ${\mathrm{row}}{,}{\mathrm{col}}{,}{\mathrm{val}}{:=}\left[\begin{array}{r}{1}\\ {3}\\ {4}\\ {1}\end{array}\right]{,}\left[\begin{array}{r}{1}\\ {1}\\ {1}\\ {2}\end{array}\right]{,}\left[\begin{array}{r}{1}\\ {7}\\ {-}{6}\\ {2}\end{array}\right]$ (8)