If you find the inv-thing quirky and complex numbers too, you can use e.g. 1 2 
1#M to duplicate a row of M. Then put something else at the copy using } 
(amend), but you were probably going to do that anyhow.

I use a verb called ins that behaves like } , except that it inserts :)

   888 (3) ins i.10
0 1 2 888 3 4 5 6 7 8 9

   2 (2) ins "1 (1) (2) ins (3 3$0)
0 0 2 0
0 0 2 0
1 1 2 1
0 0 2 0

   77 (2 5) ins i.10
0 1 77 2 3 4 77 5 6 7 8 9

I'm sure some of you can do it nicer, but my ins looks like:

   ins
1 : (':'; 'x ((+i.@#)m)}(>:(i.#y)e.m)#y')

The (+i.@#)m piece, instead of just m, is intended to allow for inserting 
multiple items, like in the last example.

Ben

________________________________________
From: [email protected] 
[[email protected]] on behalf of Sebastian 
[[email protected]]
Sent: Thursday, September 11, 2014 13:04
To: [email protected]
Subject: Re: [Jprogramming] Extend/reduce matrix dimensions

Hi Raul and Dan,

Many thanks for your great help! :)

I found # as copy in the j vocabulary now, but I cannot find #inv. Where
I have to search?

Sebastian

------ Originalnachricht ------
Von: "Raul Miller" <[email protected]>
An: "Programming forum" <[email protected]>
Gesendet: 11.09.2014 12:58:37
Betreff: Re: [Jprogramming] Extend/reduce matrix dimensions

>Here's an example of how I frequently use non-truth-valued #
>
>    9!:7]9 1 1#'+|-'
>
>Thanks,
>
>--
>Raul
>
>On Thu, Sep 11, 2014 at 6:49 AM, Dan Bron <[email protected]> wrote:
>
>>  Note also that you can use plain, uninverted # to expand arguments:
>>
>>     1 1j1 1 (#!.1) 3 3 $ 0
>>  0 0 0
>>  0 0 0
>>  1 1 1
>>  0 0 0
>>     1 1j1 1 (#!.1"1) 3 3 $ 0
>>  0 0 1 0
>>  0 0 1 0
>>  0 0 1 0
>>
>>
>>  Which approach you pick often depends on whether it's easier for you
>>to
>>  express your expansion vector with length N (complex numbers) or N+1
>>  (boolean numbers).
>>
>>  -Dan
>>
>>  This is worth remembering as well, though I rarely see it used:
>>
>>     1 2 1 # i. 3 3
>>  0 1 2
>>  3 4 5
>>  3 4 5
>>  6 7 8
>>
>>  Please excuse typos; sent from a phone.
>>
>>  > On Sep 11, 2014, at 5:32 AM, Raul Miller <[email protected]>
>>wrote:
>>  >
>>  > Here are some perhaps relevant examples:
>>  >
>>  > 1 1 0 1 #inv (3 3$ 0)
>>  > 0 0 0
>>  > 0 0 0
>>  > 0 0 0
>>  > 0 0 0
>>  > 1 1 0 1 #inv!.1 (3 3$ 0)
>>  > 0 0 0
>>  > 0 0 0
>>  > 1 1 1
>>  > 0 0 0
>>  > 1 1 0 1 #inv!.1"1 (3 3$ 0)
>>  > 0 0 1 0
>>  > 0 0 1 0
>>  > 0 0 1 0
>>  > 1 1 0 1 #inv!.1"1 (1 1 0 1) #inv!.1 (3 3$ 0)
>>  > 0 0 1 0
>>  > 0 0 1 0
>>  > 1 1 1 1
>>  > 0 0 1 0
>>  > 1 1 0 1 # 1 1 0 1 #inv!.1"1 (1 1 0 1) #inv!.1 (3 3$ 0)
>>  > 0 0 1 0
>>  > 0 0 1 0
>>  > 0 0 1 0
>>  > 1 1 0 1 #("1) 1 1 0 1 # 1 1 0 1 #inv!.1"1 (1 1 0 1) #inv!.1 (3 3$
>>0)
>>  > 0 0 0
>>  > 0 0 0
>>  > 0 0 0
>>  > (i.3) 2} 1 1 0 1 #inv (3 3$0)
>>  > 0 0 0
>>  > 0 0 0
>>  > 0 1 2
>>  > 0 0 0
>>  > (i.4) 2}"0 1 (1 1 0 1) #inv"1 (i.3) 2} 1 1 0 1 #inv (3 3$0)
>>  > 0 0 0 0
>>  > 0 0 1 0
>>  > 0 1 2 2
>>  > 0 0 3 0
>>  > (i.4) 2}"0 1 (1 1 0 1) #inv"1 (0 1 3) 2} 1 1 0 1 #inv (3 3$0)
>>  > 0 0 0 0
>>  > 0 0 1 0
>>  > 0 1 2 3
>>  > 0 0 3 0
>>  >
>>  > The whole #inv thing is a bit quirky but was quite deliberate. This
>>was a
>>  > primitive in APL, but the syntax was ... strange. Rather than
>>trying to
>>  > find a special symbol for this operation, Iverson put it on #inv
>>(since -
>>  > logically speaking - it's the inverse of #).
>>  >
>>  > Thanks,
>>  >
>>  > --
>>  > Raul
>>  >
>>  >
>>  >> On Thu, Sep 11, 2014 at 5:21 AM, Sebastian <[email protected]>
>>wrote:
>>  >>
>>  >> 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
>>
>>----------------------------------------------------------------------
>>  For information about J forums see
>>http://www.jsoftware.com/forums.htm
>>
>----------------------------------------------------------------------
>For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
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