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).
SpecialA
: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.- %F, if all
- n
Index <= ndims(A) of the dimension along which
or()
is applied / projected. By default,or()
is applied between allA
's elements. Otherwise:- n = 1 | "r" :
or()
is applied row-wise. IfA
is a matrix, the resultb
is a row, withb(j) = or(A(:,j))
- n = 2 | "c" :
or()
is applied column-wise. IfA
is a matrix, the resultb
is a column, withb(i) = or(A(i,:))
- n > 2 : If
A
is an hypermatrix with at leastn
dimensions,or()
is applied accross the nth dimension.Example: If
ndims(A)==3
andn=3
,b
is a boolean matrix of size size(A)([1 2]), withb(i,j) = or(A(i,j,:))
- n = 1 | "r" :
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 = T --> // 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 boolean matrix ( 1, 1) T ( 1, 34) T ( 1, 53) T ( 1, 96) T ( 1, 98) T --> or(A, "c") ans = ( 70, 1) sparse boolean 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 — (~) логическое НЕ
History
Версия | Описание |
6.0.0 | Complex numbers are now accepted. |
Report an issue | ||
<< norm | Матричные операции | prod >> |