SearchArray - Maple Help

ArrayTools

 SearchArray
 return the indices of nonzero elements of the given Array

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

Parameters

 A - the given Array n - (optional) number of indices returned ind - the Array stores returned indices row - the Array stores the row numbers of returned indices col - the Array stores the column numbers of returned indices val - the Array stores values of found nonzero numbers

Options

 • location=name
 one of first or last controls whether the first n or last n entries is returned when n is given. first is the default.
 • output=name
 one of index, rowcol, or rowcolval to force the desired output specification without using an assignment.

Description

 • The SearchArray(A) function returns a vector of numbers such that each element in the returned vector corresponds to an index of a nonzero entry in A.
 • The SearchArray(A, n) and SearchArray(A, n, location = first) calling sequences return a vector of the first n indices corresponding to nonzero entries in A.
 • The SearchArray(A, n, location = last) calling sequence returns a vector of the last n indices corresponding to nonzero entries in A.
 • The output specification of SearchArray, if it is on the right-hand side of an assignment, is controlled by the number of targets on the left-hand side otherwise it is controlled by the output option.
 • The row, col := SearchArray(A, ...) or SearchArray(A, output=rowcol) calling sequences return two Vectors corresponding to the paired row and column indices for nonzero entries in A.
 • The row, col, val := SearchArray(A, ...) or SearchArray(A, output=rowcolval) calling sequences return two Vectors corresponding to the paired row and column indices for nonzero entries in A and returns in the third Vector the value of the array A at each of these positions.

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}{c}{2}\\ {3}\\ {5}\\ {6}\\ {7}\end{array}\right]$ (2)
 > $\mathrm{SearchArray}\left(A,4,\mathrm{location}=\mathrm{first}\right)$
 $\left[\begin{array}{c}{2}\\ {3}\\ {5}\\ {6}\end{array}\right]$ (3)
 > $\mathrm{SearchArray}\left(A,4,\mathrm{location}=\mathrm{last}\right)$
 $\left[\begin{array}{c}{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}{cc}{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}{c}{1}\\ {3}\\ {4}\\ {1}\\ {2}\\ {4}\end{array}\right]{,}\left[\begin{array}{c}{1}\\ {1}\\ {1}\\ {2}\\ {2}\\ {2}\end{array}\right]$ (6)
 > $\mathrm{SearchArray}\left(B,'\mathrm{output}'='\mathrm{rowcol}'\right)$
 $\left[\begin{array}{c}{1}\\ {3}\\ {4}\\ {1}\\ {2}\\ {4}\end{array}\right]{,}\left[\begin{array}{c}{1}\\ {1}\\ {1}\\ {2}\\ {2}\\ {2}\end{array}\right]$ (7)
 > $\mathrm{row},\mathrm{col},\mathrm{val}≔\mathrm{SearchArray}\left(B\right)$
 ${\mathrm{row}}{,}{\mathrm{col}}{,}{\mathrm{val}}{≔}\left[\begin{array}{c}{1}\\ {3}\\ {4}\\ {1}\\ {2}\\ {4}\end{array}\right]{,}\left[\begin{array}{c}{1}\\ {1}\\ {1}\\ {2}\\ {2}\\ {2}\end{array}\right]{,}\left[\begin{array}{c}{1}\\ {7}\\ {-6}\\ {2}\\ {9}\\ {4}\end{array}\right]$ (8)
 > $\mathrm{row},\mathrm{col},\mathrm{val}≔\mathrm{SearchArray}\left(B,4\right)$
 ${\mathrm{row}}{,}{\mathrm{col}}{,}{\mathrm{val}}{≔}\left[\begin{array}{c}{1}\\ {3}\\ {4}\\ {1}\end{array}\right]{,}\left[\begin{array}{c}{1}\\ {1}\\ {1}\\ {2}\end{array}\right]{,}\left[\begin{array}{c}{1}\\ {7}\\ {-6}\\ {2}\end{array}\right]$ (9)
 > $\mathrm{SearchArray}\left(B,4,\mathrm{output}='\mathrm{rowcolval}'\right)$
 $\left[\begin{array}{c}{1}\\ {3}\\ {4}\\ {1}\end{array}\right]{,}\left[\begin{array}{c}{1}\\ {1}\\ {1}\\ {2}\end{array}\right]{,}\left[\begin{array}{c}{1}\\ {7}\\ {-6}\\ {2}\end{array}\right]$ (10)

Compatibility

 • The output option was introduced in Maple 2024.