1

Assume we have an m by n a non-square matrix. My question is this, is it possible/allowed to insert an arbitrary array ( either row or column) in such matrix so that I can obtain a square matrix? Is there a certain condition to do this or will I violate some rules if I do this? I will really appreciate your help.

flinty
  • 25,147
  • 2
  • 20
  • 86
Jimmy
  • 11
  • 1
  • 1
    This can be done, of course. Have a look at Insert and ArrayPad. Other good matrix constructors that might be helpful are Join and ArrayFlatten. – Henrik Schumacher Dec 09 '19 at 07:15
  • 1
    I'm currently working on my undergraduate thesis about inverse of a non-square matrix, I'm trying to find some pattern to establish this idea by adding/inserting arbitrary rows or columns. In line with this, I'm wondering if it is allowed to do this technique so that I can continue in my study. As I was told, only arrays with natural basis is allowed to be inserted. – Jimmy Dec 09 '19 at 07:30
  • This thread contains a lot of useful examples https://mathematica.stackexchange.com/q/3069/9469 – yarchik Oct 05 '21 at 13:02

1 Answers1

5

Here an example how to insert a row (would be easier with Insert:

A = ConstantArray[0, {5, 6}];
row = ConstantArray[1, {1, 6}];
B = Join[A[[1 ;; 2]], row, A[[3 ;;]]];
B // Dimensions

{6,6}

Alternatively, you can use

B = Insert[A, row[[1]], 3]

Here an example how to insert a row (not that easy with Insert):

A = ConstantArray[0, {6, 5}];
col = ConstantArray[1, {6, 1}];
B = Join[A[[All, 1 ;; 2]], col, A[[All, 3 ;;]], 2];
B // Dimensions

{6,6}

Henrik Schumacher
  • 106,770
  • 7
  • 179
  • 309