OK, John - I'll bite... but I'm almost embarrassed to post
this solution; I'm sure yours is just as slick!
NB. pad matrix to the "right" or "downwards":
matpad =: {.~ (2 # >./@$) NB. assumes a matrix input
(;(matpad each @ ;|:)) q
+---------+---------+---------+
|0 7 8 9 2|0 7 8 9 2|0 2 8 0 0|
|2 5 5 5 3|2 5 5 5 3|7 5 0 0 0|
|8 0 0 5 9|8 0 0 5 9|8 5 0 0 0|
| |0 0 0 0 0|9 5 5 0 0|
| |0 0 0 0 0|2 3 9 0 0|
+---------+---------+---------+
Mike
John Randall wrote:
Suppose I have a numeric matrix. How can I add rows or columns of zeros
if necessary to make it square?
I have some code that will do this, but I am embarrassed to post it.
There must be a slick way.
Thanks.
Best wishes,
John
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm