Element-by-element Not Equal (.!=)#

Purpose#

Performs element-by-element comparisons to determine if elements of the first matrix, vector, or dataframe are not equal to those of the second matrix, vector, or dataframe.

Format#

c = a .! = b()#
Parameters:
  • a (NxK matrix) – first matrix, vector, or dataframe.

  • b (LxM matrix) – second matrix, vector, or dataframe ExE compatible with a.

Returns:

c (max(N, L) by max(K, M)) – matrix of 1’s (true) and 0’s (false), where each element of c is 1 if the corresponding element of a is not equal to the corresponding element of b, otherwise 0.

Examples#

Example 1: Matrices of the same size#

// Create a 2x2 matrix
a = { 4 5,
      6 7 };

// Create another 2x2 matrix
b = { 4 5,
      7 8 };

c = a .!= b;

After the above code, c will equal:

c = 0 0
    1 1

Example 2: Matrix vs vector comparison#

If matrices are not the same size, they must be ExE conformable on one of the dimensions.

// Create a 2x3 matrix
a = { 4 5 6,
      7 8 9 };

// Create a 1x3 vector
b = { 4 8 6 };

c = a .!= b;

After the above code, c will equal:

c = 0 1 0
    1 0 1

Example 3: Row vector vs column vector comparison#

Row vectors and column vectors can be compared by expanding one to match the dimensions of the other through broadcasting.

// Create a 1x4 vector
a = { 4 5 6 7 };

// Create a 3x1 vector
b = { 4,
      6,
      7 };

c = a .!= b;

After the above code, c will equal:

c = 0 1 1 1
    1 1 0 1
    1 1 1 0

GAUSS internally expands the vectors to match each other. The above example is equivalent to comparing:

// Expanded 3x4 matrix from vector 'a'
a = { 4 5 6 7,
      4 5 6 7,
      4 5 6 7 };

// Expanded 3x4 matrix from vector 'b'
b = { 4 4 4 4,
      6 6 6 6,
      7 7 7 7 };

c = a .!= b;

This will set c equal to:

c = 0 1 1 1
    1 1 0 1
    1 1 1 0