6
$\begingroup$

Suppose I have a matrix 'mat' as

mat = Table[Subscript[m, i, j], {i, 5}, {j, 5}];
mat // MatrixForm

I want to extract the first column (or any row) as

a = mat[[All, 1]]
{Subscript[m, 1, 1], Subscript[m, 2, 1], Subscript[m, 3, 1], \
Subscript[m, 4, 1], Subscript[m, 5, 1]}

But I want the output as

{{Subscript[m, 1, 1]}, {Subscript[m, 2, 1]}, {Subscript[m, 3, 
  1]}, {Subscript[m, 4, 1]}, {Subscript[m, 5, 1]}}

How can I do that?

$\endgroup$
1
  • 2
    $\begingroup$ Note that in MMA a distinction between row and column vectors is not necessary. The reason for this is, that the dot product is cleverly defined as the contraction of the last index of the left hand side by the first index of the right hand side. $\endgroup$ Feb 16, 2021 at 14:57

2 Answers 2

6
$\begingroup$
a = mat[[All, {1}]]
{{Subscript[m, 1, 1]}, {Subscript[m, 2, 1]}, {Subscript[m, 3, 1]},
  {Subscript[m, 4, 1]}, {Subscript[m, 5, 1]}}
MatrixForm  @ a

enter image description here

$\endgroup$
0
3
$\begingroup$

Try Partition[mat[[All, 1]], 1].

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.