I agree with Ben here.  Transposing arrays of rank > 2 has never seemed intuitive to me.  Taking a single slice is just one dimension smaller than a transpose.

Say I want a slice of a 3-d array: all the atoms that have the same x index.  I should just... wait a minute, the remaining axes are y and z: what order should they have in the slice?  I might want the axes to be y then z, or z then y.  Far from being intuitive, 'slice' is ambiguous.  I have to specify the order of the remaining axes as well.  You don't notice this when you are dealing with tables, because there is only one remaining axis, but the ambiguity is always there when you deal with higher ranks.

x {"r y takes a slice of y, discarding axis r and leaving the other axes in the original order.  That's one of the (! <: # $ y) possible ways to take a slice on axis r.  If you want one that changes the order of axes, you must then apply the appropriate transpose.

In a scalar language where you have to list the order of axes every time you access an atom, the transpose is hidden beneath the index order, but it's still there.  J forces you to confront it directly.

Henry Rich



On 9/7/2023 8:44 PM, Ben Gorte wrote:
Hi Piet,

Slicing is a pretty intuitive concept so why should it be so intricate
and “hard"?
Maybe this is one of the reasons why J is not as popular as it ought to
be.

In the defence of J we might consider that the intuition of slicing is a
bit ambiguous, which is the dangerous sort.

The mental model of a 3d array for some might be a booklet of printed pages
on the desk in front of them. Indexing would be along [pages, lines,
columns], with the origin at the top-far-left corner. However, others might
have put the pages on the desk one by one and have page 0 at the bottom.

I don't know about your application, but extra sympathy should go out to
those who think about 3D in terms of x,y,z. The intuitive [page, line,
column] correspond to their z, y and x, in that order. Moreover, x
increases left to right, like column, but y goes opposite to line, and z
opposite to page - the latter for some but not for others.

Personally I have been working long and hard on the representation of 3D
geographic scenes as 3d voxel arrays, and (hopefully) just before getting
completely crazy from the above I decided to call my 3D-array indices
[X,Y,Z] and stick to it.

It helped; I regard my models as collections of vertical columns (the z
dimension), spread over the (x,y) space, and I think that is perfectly
intuitive. However, now I have verbs called Top, Front and Side, I think
similar to what Piet was asking for, that generate 2D views and
cross-sections of 3D voxel models ("viewmat Top scene", "viewmat Front
building" etc.). What happens inside those is still a bit weird.

Greetings,
Ben


On Fri, 8 Sept 2023 at 07:10, Piet de Jong <pietd...@gmail.com> wrote:

Thanks for all the great suggestions which has helped me a lot.

To my mind it does raise a couple of issues or questions.

I’ll stick my head out with them, knowing there might be much blowback.
But bear with me.

Slicing is a pretty intuitive concept so why should it be so intricate and
“hard"?

Maybe this is one of the reasons why J is not as popular as it ought to be.

I “love” J and always use it.

But I have not been able to convince a single other person to take it up.

I’m always wondering why?   Does it mean it’s just too intricate for the
average Joe.
Most people on this forum I imagine love the intricacy and see it as an
enjoyable challenge.

But the average Joe just wants to solve problems as quickly as possible
and get on with life, not waste time on challenging intricate puzzles.

So perhaps J is too much “puzzle solving” rather than “problem solving”

Notwithstanding the above — I’ll always stick with J.


On 8 Sep 2023, at 04:22, Jose Mario Quintana <
jose.mario.quint...@gmail.com> wrote:
Oops, I forgot o=. @:

On Thu, Sep 7, 2023 at 1:27 PM Jose Mario Quintana <
jose.mario.quint...@gmail.com> wrote:

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.
The answer might depend on the intended usage of the verb that you have
in
mind. If, for example,
you want to preserve the order of the remaining axes, then Henry's
suggestion modified by Raul would work,

   $ Y=. i.2 3 4 5
2 3 4 5

   slicep=. ~.@(, i.@#@$) |: ]

   (0 1 2 3) ($ o slicep"0 _) Y
2 3 4 5
3 2 4 5
4 2 3 5
5 2 3 4

Another possibility is to rotate the axes,

   slicer=. (|. i.@:#@:$@:]) |: ]

   (0 1 2 3) ($ o slicer"0 _) Y
2 3 4 5
3 4 5 2
4 5 2 3
5 2 3 4

I hope this helps


On Wed, Sep 6, 2023 at 7:58 PM 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