I think it would need specifying rank 0 and using /.
   m=: i. 5 4 3
   0 2 {"0 2/ m NB. slices 0 2 at rank 2
 0  1  2
12 13 14
24 25 26
36 37 38
48 49 50

 6  7  8
18 19 20
30 31 32
42 43 44
54 55 56
   slice =: {{ {"(0,m)/ }} NB. the same
   $0 2(3 slice) m
2 5 3

This way, the number of slices is the first dimension, and the remaining
are the slices remain in order, i.e. with the sliced dimension taken out
(which is most natural to me).
If you'd like to keep the dimensions in order, and still take a list of
indices, you'd have to apply rank (") twice:

   dice=: {{ {"(0 _)"(_,m) }}
   $0 2(2 dice) m  NB. $m being 5 4 3
5 2 3

The outer rank _ m selects the right rank to dice at, while passing on the
entire list of indices. The inner rank 0 _ allows for getting a slice for
each index, and is applied to every slice.

I hope one of these works for you.
Jan-Pieter

On Thu, 7 Sept 2023, 03:21 'Rob Hodgkinson' via Programming, <
programm...@jsoftware.com> wrote:

> I should have read Henry’s more carefully (sorry Henry), very similar
> approach, bust the display of the ‘slices’ differs.
>
>    1 HR a
>  0 12
>  4 16
>  8 20
>
>  1 13
>  5 17
>  9 21
>
>  2 14
>  6 18
> 10 22
>
>  3 15
>  7 19
> 11 23
>
>    1 T a
>  0  1  2  3
> 12 13 14 15
>
>  4  5  6  7
> 16 17 18 19
>
>  8  9 10 11
> 20 21 22 23
>
> > On 7 Sep 2023, at 10:57 am, 'Rob Hodgkinson' via Programming <
> programm...@jsoftware.com> wrote:
> >
> > Very nice Ben, your TT is “hard coded to rank 3”, so fails on other than
> rank 3.
> > I “tinkered” by replacing 0 1 2 with i. $ $, and converted to tacit
> using 13 : which worked, but less readable...
> >
> >   ]a=:i.2 3 4
> > 0  1  2  3
> > 4  5  6  7
> > 8  9 10 11
> >
> > 12 13 14 15
> > 16 17 18 19
> > 20 21 22 23
> >   ]b=:i.2 2
> > 0 1
> > 2 3
> >
> >   T=:{{((i. $ $ y)-.x) |: y}}        NB. Generalised 0 1 2 to (i. Rank y)
> >
> >   0 1{1 T a
> > 0  1  2  3
> > 12 13 14 15
> >
> > 4  5  6  7
> > 16 17 18 19
> >
> >   0 1{1 T b                             NB. Your original function
> failed here on rank 2
> > 0 2
> > 1 3
> >
> >   TT=:13 : '((i. $ $ y)-.x) |: y’
> >   TT
> > ] |:~ [ -.~ [: i. [: # [: $ ]
> >
> >   0 1{1 TT a
> > 0  1  2  3
> > 12 13 14 15
> >
> > 4  5  6  7
> > 16 17 18 19
> >
> >   0 1{1 TT b
> > 0 2
> > 1 3
> >
> >
> > Impressive solution Ben (strong scent of APL in there !)… well done.
> >
> > Piet does this do what you want ?
> >
> > Best, Rob
> >
> >> On 7 Sep 2023, at 10:22 am, Ben Gorte <bgo...@gmail.com> wrote:
> >>
> >> Still not quite sure what you mean, but how about:
> >>
> >> ]n =: i.2 3 4
> >>
> >> 0 1 2 3
> >>
> >> 4 5 6 7
> >>
> >> 8 9 10 11
> >>
> >>
> >> 12 13 14 15
> >>
> >> 16 17 18 19
> >>
> >> 20 21 22 23
> >>
> >>
> >> 1{0 T n NB. -: 1{n
> >>
> >> 12 13 14 15
> >>
> >> 16 17 18 19
> >>
> >> 20 21 22 23
> >>
> >>
> >> 1{1 T n
> >>
> >> 4 5 6 7
> >>
> >> 16 17 18 19
> >>
> >>
> >> 1{2 T n
> >>
> >> 1 5 9
> >>
> >> 13 17 21
> >>
> >> If that's the one, then T would be:
> >>
> >> T =: {{ (0 1 2-.x) |: y }}
> >>
> >>
> >> (sorry, not tacit)
> >>
> >>
> >> Ben
> >>
> >> On Thu, 7 Sept 2023 at 09:58, Piet de Jong <pietd...@gmail.com> wrote:
> >>
> >>> This works!
> >>> Except the ordering of the axes is slightly unusual to my way of
> thinking.
> >>> For example suppose m=.i.3 3 3 is the “cube" be sliced and v is your
> verb.
> >>> Then the items of (0 v m) has successive items  “going back” into the
> cube.
> >>> The items (1 v m) are the horizontal slices.
> >>> The items of (2 v m) are the vertical slices.
> >>>
> >>> The order of the last two appear "unnatural".  (To my way of thinking
> at
> >>> least)
> >>> This seems to beg the question what is the natural order when  slicing.
> >>>
> >>>> On 7 Sep 2023, at 08:32, Henry Rich <henryhr...@gmail.com> wrote:
> >>>>
> >>>> Since you want all the slices, what you are looking for is a
> transpose.
> >>>>
> >>>> Maybe
> >>>>
> >>>> ~.@(, i.@#) |: ]
> >>>>
> >>>> Untested.
> >>>>
> >>>> Henry Rich
> >>>>
> >>>> On Wed, Sep 6, 2023, 6:10 PM Piet de Jong <pietd...@gmail.com> wrote:
> >>>>
> >>>>> Here is my “wish"
> >>>>>
> >>>>> A dyadic (tacit) verb such that x v y gives all the slices of y along
> >>>>> dimension x, where x is integer.   That is to say
> >>>>>
> >>>>> i{ x v y
> >>>>>
> >>>>> is slice i of the array y along dimension x.
> >>>>>
> >>>>> Thanks for all your help!
> >>>>>
> >>>>>> On 7 Sep 2023, at 08:04, 'robert therriault' via Programming <
> >>>>> programm...@jsoftware.com> wrote:
> >>>>>>
> >>>>>> Or something like this?
> >>>>>>
> >>>>>> [n =. i. 2 2 2
> >>>>>> 0 1
> >>>>>> 2 3
> >>>>>>
> >>>>>> 4 5
> >>>>>> 6 7
> >>>>>> ,./ n
> >>>>>> 0 1 4 5
> >>>>>> 2 3 6 7
> >>>>>> ($ $ (,@,./)) n
> >>>>>> 0 1
> >>>>>> 4 5
> >>>>>>
> >>>>>> 2 3
> >>>>>> 6 7
> >>>>>>
> >>>>>> Cheers, bob
> >>>>>>
> >>>>>>
> >>>>>>> On Sep 6, 2023, at 14:49, 'robert therriault' via Programming <
> >>>>> programm...@jsoftware.com> wrote:
> >>>>>>>
> >>>>>>> Hi Piet,
> >>>>>>>
> >>>>>>> Maybe show us what you would want to do with higher dimensions? Or
> a
> >>>>> less symmetric 2 dimensional shape?
> >>>>>>>
> >>>>>>> For shape 2 2, I would use the even simpler
> >>>>>>>
> >>>>>>> |: m
> >>>>>>> 0 2
> >>>>>>> 1 3
> >>>>>>>
> >>>>>>> Hope this helps.
> >>>>>>>
> >>>>>>> Cheers, bob
> >>>>>>>
> >>>>>>>> On Sep 6, 2023, at 14:26, Brian Schott <schott.br...@gmail.com>
> >>> wrote:
> >>>>>>>>
> >>>>>>>> ,./0 1 {"1  m
> >>>>>>>
> >>>>>>>
> ----------------------------------------------------------------------
> >>>>>>> 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
> >
> > ----------------------------------------------------------------------
> > 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