TransWikia.com

How to extract a column (or a row) of a matrix as another column vector/ column matrix (or a row vector), not as a list?

Mathematica Asked by PoreyS on March 19, 2021

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?

2 Answers

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

Correct answer by kglr on March 19, 2021

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

Answered by Michael Poulshock on March 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP