Devon has shown how to do the scatter-read you asked for.  If you want full rows or columns, use other forms.  In your case, where you have a table (x) where each row is an index list, use

x (<"1@[ { ]) array

to avoid creating the individual boxed index-lists.  You can assign (<"1@[ { ]) to a name.

Henry Rich

On 6/7/2020 12:48 PM, Devon McCormick wrote:
    I. ,map
8 11 25
    ]ixs=. ($map) #: I. ,map
1 2
1 5
4 1
    map{~<"1 ixs
1 1 1

The same expression works for higher-dimensional arrays as well.


On Sun, Jun 7, 2020 at 12:41 PM <xash@λ.land> wrote:

Hello everyone,

I'm new to J and while working with 1d indices feels quite natural, using
multidimensional indices not so. For example, finding the indices
(3 2$1 2,1 5,4 1) of #'s in this bit mask^Wmap:

     map=:'#'= [;._2 (0 : 0)
......
..#..#
......
......
.#....
......
)

With 1d indices it would be `linear=:I.;map`. But to get the 2d indices the
result of I. needs to be intertwined with row numbers as I. only
operates on lists:
     points=:; (i.#map) ,"0/each <&I. map
– and this won't even generalize to more dimensions.

To reverse this and built back a bit map, instead of `1 linear}($map)$0`
I'd use
     1 (<"1 points)}($map)$0
though this is wrong if points='', as then with `1 (<'')}…` the whole
map is set to 1.  So it's actually
     1 (<"1^:(*@#) points)} ($map)$0

With the 2d version of `linear{map` it's even more complicated, as `''{map`
returns not nothing but an empty axis with shape 0 6, so output needs to be
checked, too.

Before I built up too many inefficient helper functions: what is the usual
approach to this?  I could drop to 1d indices and convert when needed
(what is the manhattan distance between 12 and 16?), but for this I then
need
the dimensions of map all over the place to get back x/y coordinates and
this doesn't feel right either.

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




--
This email has been checked for viruses by AVG.
https://www.avg.com

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

Reply via email to