Picks out those elements of raw of matrix for which the corresponding element of vector is True.

130 Views Asked by At

I want to define a mathematical definition for this process

Illustrative example, consider the matrix $A$

$A=\left( \begin{array}{ccccc} 1 & 0 \\ 0 & 1 \\ 1 & 1 \\ \end{array} \right)$ and $V=(1,0,1)$

I suppose

$$B=A^T=(r_1,r_2,r_3)^T$$

Then $B=((1,0),(0,1),(1,1))$. I need to pick the row of matrix $B$ iff the corresponding element of vector $V$ is $1$ $($one$)$. Then we get $$Pick_B=\{(1,0),(1,1)\}$$

Is it a mathematical formulation of this process. Or a better mathematical expression. I needed help writing the text for this definition in mathematical form. Can you help me formulate a definition in general.

2

There are 2 best solutions below

2
On

I am not sure if I understood correctly, but if you need to pick the rows of $B=\begin{pmatrix}1 & 0\\ 0& 1\\ 1& 1\end{pmatrix}$ corresponding to the positions of the numbers $1$ within the vector $V=(1,0,1)$, you can do the following.

Define the matrix $N(V)=\begin{pmatrix}1 & 0 & 0\\ 0&0& 1\end{pmatrix}$ (There is only one 1 on each row and the rows add up to V) then the rows of $N(V)B=\begin{pmatrix}1 & 0\\ 1& 1\end{pmatrix}$ are the the required rows.

1
On

As @Daniel wrote, it suffices to construct $N(V)$ where $V=[v_1,\cdots,v_n]^T$

"$\textbf{.}$" denotes the Hadamard product.

Step 1. $(V[1,\cdots,1])\textbf{.} I_n=diag(v_1,\cdots,v_n)$.

step 2. remove the zero rows of the previous result. This is a job for logical indexing. I don't think that there exist standard non-logical operations that do the job.

EDIT. An example. Let $V=[a,0,b,0]^T$, where $a,b\not= 0$.

Step 1. Let $D=(V[1,1,1,1])\textbf{.}I_4=\begin{pmatrix}a&a&a&a\\0&0&0&0\\b&b&b&b\\0&0&0&0\end{pmatrix}\textbf{.}I_4=diag(a,0,b,0)$.

step 2. For every zero diagonal entry of $D$, we remove the row where it stands, that is $N(V)=\begin{pmatrix}a&0&0&0\\0&0&b&0\end{pmatrix}$