Click or drag to resize

DoubleMatrixFindNonzero Method

Searches for nonzero entries in this instance, and returns their zero-based linear indexes.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public IndexCollection FindNonzero()

Return Value

Type: IndexCollection
The collection of zero-based linear indexes of the nonzero entries of this instance, if found; otherwise null.
Remarks

Matrix entries are interpreted as well ordered following a column major ordering. The position of an entry in such well ordering is referred to as the linear position of that entry.

Examples

In the following example, the nonzero entries of a data matrix are found.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class FindNonzeroExample0  
    {
        public void Main()
        {
            // Create a matrix.
            var data = new double[6] {
                0,  2,
                2,  0,
                0,  4,
            };
            var matrix = DoubleMatrix.Dense(3, 2, data, StorageOrder.RowMajor);
            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            // Find the linear indexes of nonzero entries in data.
            var indexes = matrix.FindNonzero();

            Console.WriteLine();
            Console.WriteLine("Linear indexes of nonzero entries in data:");
            Console.WriteLine(indexes);

            // FindNonzero is available for read-only matrices:
            // find nonzero entries using a read-only wrapper of the data matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();
            indexes = readOnlyMatrix.FindNonzero();

            Console.WriteLine();
            Console.WriteLine("Using read-only data. Linear indexes of nonzero entries:");
            Console.WriteLine(indexes);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// 0                2                
// 2                0                
// 0                4                
// 
// 
// 
// Linear indexes of nonzero entries in data:
// 1, 3, 5
// 
// Using read-only data. Linear indexes of nonzero entries:
// 1, 3, 5

See Also