How to insert a column into a matrix, the correct Mathematica way

前端 未结 5 1398
旧时难觅i
旧时难觅i 2021-01-30 14:40

I think Mathematica is biased towards rows not columns.

Given a matrix, to insert a row seems to be easy, just use Insert[]

(a = {{1, 2, 3},         


        
5条回答
  •  深忆病人
    2021-01-30 15:15

    You can use Join with a level specification of 2 along with Partition in subsets of size 1:

    a = {{1, 2, 3}, {4, 0, 8}, {7 , 8, 0}}
    column = {97, 98, 99}
    newa = Join[a,Partition[column,1],2]
    

提交回复
热议问题