# How can I find a column vector in a matrix?

This may be a simple question, but how can I find a column vector in a matrix? As an example, A = {{1, 2}, {0, 1}} b = {1, 0}; $$\\ A=\biggl( \begin{matrix} 1 & 2 \\ 0 & 1 \end{matrix} \biggr)$$ $$\\ b=\biggl( \begin{matrix} 1 \\ 0 \end{matrix} \biggr)$$

• A[[All,1]] gives the first column of the matrix A. Look at ‘Part’ for other ways to index into lists and matrices – bill s Sep 30 '17 at 3:20
• Why not transpose the matrix and find a row instead? – J. M. is in limbo Sep 30 '17 at 3:52
• Thank you both. Unfortunately, I can't figure out how to use Part to actually find the index of the pertinent column instead of checking each column against b. I will try transposing the matrix though, thanks. – BJParks Sep 30 '17 at 18:11
• why is every one making this simple operation so complicated? :) Bill comment above is all what is needed. A[[ All , columnNumber ]] This maps 1:1 to Matlab A(:,ColumnNumber) Except Mathematica uses [[ for Matlabs ( and All for Matlab : – Nasser Sep 30 '17 at 20:34
• @Nasser, I was assuming this was a toy example, and OP does need to find out which column of a given matrix is identical to a given list, in which case transposition is a useful first step. – J. M. is in limbo Sep 30 '17 at 22:05

A = {{1, 2, 1}, {0, 1, 0}};
b = {1, 0};
Pick[Range[Length[First[A]]], Transpose[A], b]


{1, 3}

• Thank you! This does exactly what I need. – BJParks Sep 30 '17 at 19:34
• I personally would've used Last[Dimensions[A]] instead of Length[First[A]]. – J. M. is in limbo Oct 1 '17 at 7:07

One method as suggested by J.M. (written two equivalent ways):

hk = Partition[A // Transpose, Length[A[[All, 1]]]] // Transpose;
{{c, d}} = Position[hk, b];
A[[All,c]]

{{c, d}} =  Position[Transpose[Partition[Transpose[A], Length[A[[All, 1]]]]], b]
A[[All,c]]

• Why are you using Partition? Couldn't you simply Position[A\[Transpose], b]? – Szabolcs Sep 30 '17 at 19:07
• Thank you, this works very well also; I didn't realize that Position could be used like that. – BJParks Sep 30 '17 at 19:38