Multik 0.3.0 Help

Logical operations

Overview

Multik provides two element-wise logical operations: and and or. Both are infix functions that accept two arrays of the same shape and return an NDArray<Int, D> where each element is 1 (true) or 0 (false).

and

infix fun <T : Number, D : Dimension> MultiArray<T, D>.and( other: MultiArray<T, D> ): NDArray<Int, D>

Returns an Int array where each element is the logical AND of the corresponding elements.

Truth rules

Type

False value

True value

Int, Long, Short, Byte

0

Non-zero (bitwise AND)

Float, Double

0.0 or NaN

Non-zero, non-NaN

Example

val a = mk.ndarray(mk[1, 0, 3, 0]) val b = mk.ndarray(mk[1, 1, 0, 0]) val c = a and b // [1, 0, 0, 0]

or

infix fun <T : Number, D : Dimension> MultiArray<T, D>.or( other: MultiArray<T, D> ): NDArray<Int, D>

Returns an Int array where each element is the logical OR of the corresponding elements.

Example

val a = mk.ndarray(mk[1, 0, 3, 0]) val b = mk.ndarray(mk[1, 1, 0, 0]) val c = a or b // [1, 1, 1, 0]

Pitfalls

  • Both arrays must have the same shape.

  • For integer types, bitwise AND/OR is used — 2 and 1 yields 0 (bitwise), not 1.

  • Float/Double NaN is treated as false.

  • The return type is always NDArray<Int, D>, regardless of the input type.

28 February 2026