Is there a math operator to see if all vector element values are positive?

720 Views Asked by At

So I want to check if all vector values are positive and if they are get 1 else a 0. Is there an operator for that or one must use a picewize function?

So $P[1,2,0]^t = 1$

while

$P[-1,0,0]^t = 0$

2

There are 2 best solutions below

0
On

To test whether each component is positive is equivalent to testing if the minimum is positive.:$$Px = \mathbb{1}_{\min_i x_i >0}$$

0
On

If the vector $\vec P$ has $N$ components then

$$ T \equiv \sum_{k=1}^N \big ( |P_k|-P_k \big) =0 $$

if and only if all components are non-negative.

a function that gives the values you want can be expressed as $(T = 0)$ understood as a boolean function returning 1 for true and 0 for false