Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.0 - Português

Change language to:
English - Français - 日本語 - Русский

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function

Ajuda do Scilab >> Funções Elementares > Matrix operations > or

or

logical OR over the elements of a boolean or numerical array

Syntax

b = or(A)
b = or(A, 'r')
b = or(A, 'c')
b = or(A, n)

Arguments

A

vector, matrix, or hypermatrix of booleans, encoded integers (of any inttype), real, or complex numbers. A may be sparse-encoded.

A number is considered as %F (false) if it is 0 or 0+0i. Otherwise (including %nan), it is equivalent to %T (true).

Special A:
  • or([]) returns %F.
  • or(%nan) returns %T.
b

boolean scalar, if or(A) is used without any option "r", "c", n. It is set to

  • %F, if all A's components are %F or zero.
  • %T, otherwise (at least one A's component is %T or non-zero).

Otherwise: boolean vector, matrix or hypermatrix.

When A is sparse-encoded, b is so as well.

n

Index <= ndims(A) of the dimension along which or() is applied / projected. By default, or() is applied between all A's elements. Otherwise:

  • n = 1 | "r" : or() is applied row-wise. If A is a matrix, the result b is a row, with b(j) = or(A(:,j))
  • n = 2 | "c" : or() is applied column-wise. If A is a matrix, the result b is a column, with b(i) = or(A(i,:))
  • n > 2 : If A is an hypermatrix with at least n dimensions, or() is applied accross the nth dimension.

    Example: If ndims(A)==3 and n=3, b is a boolean matrix of size size(A)([1 2]), with b(i,j) = or(A(i,j,:))

Description

or() computes a logical OR between the components of the single input A.

To compute OR in an element-wise way between two arrays C and D of same sizes, please use the | operator instead.

Why is or([]) equal to %F ? Whatever are compatible B and C, or([B C]) == (or(B) | or(C)). Now, for B = [], or([B C]) == or(C). To have always (or([]) | or(C))==or(C) whatever is C, or([]) must be %F.

Examples

or([])
or(0)
or(0+0*%i)
or(%eps)
or(%i)
or(%nan)

// Projection accross a dimension / along a direction:
A = rand(2,5)<0.3
or(A)
or(A, "r")   // or(A, 1) does the same
or(A, "c")   // or(A, 2) does the same

// Equivalent application to encoded integers:
A = int16(grand(3,5,"uin",-10,10));
A(abs(A)<8) = 0
or(A)
or(A,1)

// With an hypermatrix of decimal numbers:
A = rand(3,4,2);
A(A<0.7) = 0
or(A,3)

// With a sparse matrix:
A = sprand(70,100, 0.001)
or(A, "r")
or(A, "c")
--> or([])
 ans  =
  F

--> or(0)
 ans  =
  F

--> or(0+0*%i)
 ans  =
  F

--> or(%eps)
 ans  =
  T

--> or(%i)
 ans  =
  T

--> or(%nan)
 ans  =
  F           // %T expected => Bug 14522

--> // Projection accross a dimension / along a direction:
--> A = rand(2,5)<0.3
 A  =
  T F F F F
  F F T F F

--> or(A)
 ans  =
  T

--> or(A, "r")   // or(A, 1) does the same
 ans  =
  T F T F F

--> or(A, "c")   // or(A, 2) does the same
 ans  =
  T
  T

--> // Equivalent application to encoded integers:
--> A = int16(grand(3,5,"uin",-10,10));
--> A(abs(A)<8) = 0
 A  =
  0  0  0 -9  0
  0 10  0  0  0
  0  0  0  0  9

--> or(A)
 ans  =
  T

--> or(A,1)
 ans  =
  F T F T T


--> // With an hypermatrix of decimal numbers:
--> A = rand(3,4,2);
--> A(A<0.7) = 0
 A  =
(:,:,1)
   0.   0.       0.   0.
   0.   0.7065   0.   0.7227
   0.   0.       0.   0.8977
(:,:,2)
   0.       0.   0.       0.7901
   0.       0.   0.       0.9809
   0.9677   0.   0.7795   0.8187

--> or(A,3)
 ans  =
  F F F T
  F T F T
  T F T T


--> // With a sparse matrix:
--> A = sprand(70,100, 0.001)
 A  =
(  70,  100) sparse matrix

(  18,  53)   0.7943
(  23,  96)   0.4361
(  38,  34)   0.9275
(  56,   1)   0.1622
(  69,  98)   0.3112

--> or(A, "r")
 ans  =
(  1,  100) sparse matrix

(  1,   1)  T
(  1,  34)  T
(  1,  53)  T
(  1,  96)  T
(  1,  98)  T

--> or(A, "c")
 ans  =
(  70,  1) sparse matrix

(  18,  1)  T
(  23,  1)  T
(  38,  1)  T
(  56,  1)  T
(  69,  1)  T

See also

  • | (element-wise) — Binary OR between integers. Logical OR over/between booleans and numbers
  • and — logical AND between the elements of a boolean or numerical array
  • ~ not — (~) não lógico
Report an issue
<< norm Matrix operations prod >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 14 15:09:42 CET 2017