as nice as # inv is, you may find this adverb more flexible and intuitive:

insertitem =: 1 : '(u"_ {. ]) , [ , u"_ }. ]'

the adverb argument is a verb that tells which item position to insert.  The 
verb argument is dyadic, but can be a constant verb.  Add @:] to it to just use 
y as the argument To insert columns, you would transpose first, to make the 
columns the items.

   1 2: insertitem &.|: 3 3 $ 0 
0 0 1 0 
0 0 1 0 
0 0 1 0 

    1 2 3 2: insertitem &.|: 3 3 $ 0 
0 0 1 0 
0 0 2 0 
0 0 3 0 

   1 2: insertitem 1 2: insertitem &.|: 3 3 $ 0 
0 0 1 0 
0 0 1 0 
1 1 1 1 
0 0 1 0 


deleteitem =: {. , >:@[ }. ]  NB. verb

   2 deleteitem 2 deleteitem &.|: 1 2: insertitem 1 2: insertitem &.|: 3 3 $ 0 
0 0 0 
0 0 0 
0 0 0


----- Original Message -----
From: Sebastian <[email protected]>
To: "[email protected]" <[email protected]>
Cc: 
Sent: Thursday, September 11, 2014 5:21 AM
Subject: [Jprogramming] Extend/reduce matrix dimensions

Hi,

I know the verbs , ,. ,: to add rows, columns and dimensions to 
matrices. It is easy to add these to begin or the end of the 
corrosponding dimension, but what is to do, if I want to add one 
row/column in the middle of a matrix? Is the only way to slice the 
matrix in two pieces and join them with the new row/column?

A few examples:

Initial situation:

3 3 $ 0
0 0 0

0 0 0

0 0 0


add column somewhere to the middle:

0 0 1 0

0 0 1 0

0 0 1 0



add row somewhere to the middle:

0 0 1 0

0 0 1 0

1 1 1 1

0 0 1 0


remove the added column:

0 0 0

0 0 0

1 1 1

0 0 0



and the row:



0 0 0

0 0 0

0 0 0



Can anyone help me with this?



Regards

Sebastian
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to