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.
Asked
Active
Viewed 279 times
1
1 Answers
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
-
The B = Insert[A, row, 3] version requires a 1-dimensional List: row = ConstantArray[1, {6}]. – Romke Bontekoe Oct 05 '21 at 06:46
-
InsertandArrayPad. Other good matrix constructors that might be helpful areJoinandArrayFlatten. – Henrik Schumacher Dec 09 '19 at 07:15