GNU Octave Manual Version 3 by John W. Eaton, David Bateman, Søren Hauberg Paperback (6"x9"), 568 pages ISBN 095461206X RRP £24.95 ($39.95) |
20.1.3 Sparse Matrix Properties
There are a number of functions that return basic information
concerning sparse matrix objects. The most basic of these is
issparse
which identifies whether a particular Octave object is
a sparse matrix.
The function nnz
returns the number of non-zero entries in a
sparse matrix, and nzmax
returns the amount of storage allocated
to it.
The function spstats
returns some basic statistics on the
columns of a sparse matrix, including the number of elements, mean
value and variance of each column.
- Loadable Function: issparse (expr)
- Return 1 if the value of the expression expr is a sparse matrix.
- Function File: nonzeros (s)
- Returns a vector of the non-zero values of the sparse matrix s.
- Built-in Function: scalar = nnz (a)
- Returns the number of non zero elements in a.
See also sparse
- Built-in Function: scalar = nzmax (SM)
- Return the amount of storage allocated to the sparse matrix SM.
Note that Octave tries to free unused memory at the first opportunity
for sparse objects. The values returned by nzmaz and nnz
will typically be the same, although they may differ for user-created sparse objects.
See also sparse, spalloc
- Mapping Function: spmax (x, y, dim)
- Mapping Function: [w, iw] = spmax (x)
- For a vector argument, return the maximum value. For a matrix
argument, return the maximum value from each column, as a row
vector, or over the dimension dim if defined. For two matrices
(or a matrix and scalar), return the pair-wise maximum.
Thus,
max (max (x))
returns the largest element of x, and
max (2:5, pi) => 3.1416 3.1416 4.0000 5.0000
compares each element of the range
2:5
withpi
, and returns a row vector of the maximum values.For complex arguments, the magnitude of the elements are used for comparison.
If called with one input and two output arguments,
max
also returns the first index of the maximum value(s). Thus,[x, ix] = max ([1, 3, 5, 2, 5]) => x = 5 ix = 3
- Mapping Function: spmin (x, y, dim)
- Mapping Function: [w, iw] = spmin (x)
- For a vector argument, return the minimum value. For a matrix
argument, return the minimum value from each column, as a row
vector, or over the dimension dim if defined. For two matrices
(or a matrix and scalar), return the pair-wise minimum.
Thus,
min (min (x))
returns the smallest element of x, and
min (2:5, pi) => 2.0000 3.0000 3.1416 3.1416
compares each element of the range
2:5
withpi
, and returns a row vector of the minimum values.For complex arguments, the magnitude of the elements are used for comparison.
If called with one input and two output arguments,
min
also returns the first index of the minimum value(s). Thus,[x, ix] = min ([1, 3, 0, 2, 5]) => x = 0 ix = 3
- Function File: [count, mean, var] = spstats (s)
- Function File: [count, mean, var] = spstats (s, j)
- Return statistics for the non-zero elements of the sparse matrix s.
count is the number of non-zeros in each column, mean
is the mean of the non-zeros in each column, and var is the
variance of the non-zeros in each column.
Called with two input arguments, if s is the data and j is the bin number for the data, compute the statistics for each bin. In this case, bins can contain data values of zero, whereas with
spstats (s)
the zeros are not included.
ISBN 095461206X | GNU Octave Manual Version 3 | See the print edition |