not — Compute element-wise logical negation.
not(A) and ~A invert the zero/nonzero truth value of every supported element.
Syntax
tf = not(A)Inputs
A- Type
Any- Required
- Yes
- Description
- Logical, numeric, character, complex, table, or timetable input.
Returns
tf- Type
Any- Description
- Logical negation with the input array shape or tabular container.
Errors
RunMat:not:InvalidInput- When
- The input is not supported logical, numeric, character, complex, table, timetable, or resident numeric data.
- Message
not: unsupported input type
Truth and shape semantics
not(A) and ~A invert each element's zero/nonzero truth value. Zero becomes true; every nonzero numeric value, including NaN and a complex value with either component nonzero, becomes false.
All eight fixed-width integer classes are tested directly in authoritative storage. Array shape and empty geometry are preserved.
Tables and accelerated execution
Tables and timetables apply not independently to every supported variable and retain their container metadata.
A supported same-owner provider operation remains resident. Unsupported provider routes gather exactly; explicitly requested residency is restored only after validating owner, device, shape, storage, and aliasing.
Examples
Negate a scalar condition
tf = not(5)Expected output:
tf = falseInvert a logical mask
tf = not(logical([1 0 1]))Expected output:
tf = [false true false]Invert numeric truth values
tf = not([0 1 NaN 0])Expected output:
tf = [true false false true]Evaluate wide integers exactly
x = [uint64(0) intmax('uint64')];
tf = not(x)Expected output:
tf = [true false]Invert character code points
tf = not(['A' 0 'C'])Expected output:
tf = [false true false]Invert complex truth values
tf = not([0+0i 1+0i 0+2i])Expected output:
tf = [true false false]Invert table variables
T = table([0; 2], [1; 0], 'VariableNames', {'A', 'B'});
R = not(T)Expected output:
R is a table with logical variablesKeep a supported result resident
A = gpuArray([0 2 0]);
G = not(A);
tf = gather(G)Expected output:
G remains resident and tf = [true false true]Using not with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how not changes the result.
Run a small not example, explain the result, then change one input and compare the output.
FAQ
What does not return?⌄
A scalar operand produces a logical scalar; an array produces a logical array; a tabular operand retains its table or timetable container with logical variables.
How are NaN and complex values interpreted?⌄
NaN is nonzero. A complex value is true when either component is nonzero. not returns false for either case.
What happens to empty arrays?⌄
The result is an empty logical array with the same shape.
Are integers converted to double?⌄
No. Integer zero/nonzero truth is read directly from each fixed-width class.
How are tables handled?⌄
The operation is applied variable by variable and retains the table or timetable class and metadata.
Can execution remain on a GPU?⌄
Yes when an exact owning provider supports logical negation. Exact fallback preserves explicit gpuArray intent after validating the restored result.
Related Logical functions
Source you can read
Every RunMat function's source is public. Read exactly how not is executed, line by line, in Rust.
- View the source for not in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.