4%~a-4|a

 

    Den 6:27 onsdag den 11. januar 2017 skrev Skip Cave 
<s...@caveconsulting.com>:
 
 

 Ben, Jose, Raul, Roger,

Thanks so much for your efforts in providing various solutions to my index
problem.
I am continually amazed at the diversity of options that J's primitives
provide to approach problems.

Ben:
4$.$. i.3 4  NB. Unboxed using Sparse
NB. Wow! I would have never even thought of trying Sparse!

{i. each $ i. 3 4  NB.Boxed using Each
NB. Very similar to Roger's solution.

Jose:
>L:1@:{::@:(<"0)@:i. 3 4
NB.  Boxed. Whew! Lots of tacit stuff. Above my pay grade!

Roger:
{i.&.> 3 4  NB. Boxed, minimal, elegant.

Raul:
3 4 #: i. 3 4 NB. Unboxed using Encode

Skip Cave
Cave Consulting LLC

On Tue, Jan 10, 2017 at 5:05 PM, Skip Cave <s...@caveconsulting.com> wrote:

> Given a 3x4 matrix:
>
>
>
>  a =. i. 3 4
>
>  a
>
> 0 1  2  3
>
> 4 5  6  7
>
> 8 9 10 11
>
>
>
> I can get the horizontal indices:
>
>
>
>    4|a
>
> 0 1 2 3
>
> 0 1 2 3
>
> 0 1 2 3
>
>
>
>
>
> How do I get the vertical indices?
>
>
>
>  3?a  NB. The question-mark represents the unknown verb
>
> 0 0 0 0
>
> 1 1 1 1
>
> 2 2 2 2
>
>
>
> Ultimately, I want to design a verb bix, that will take a list of
> dimensions of any length, and generate boxed indices of the resulting
> array. The number of integers in each box will be the same as the rank of
> the array:
>
>
>
>
>  bix 10
>
> ┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
>
> │0│1│2│3│4│5│6│7│8│9│
>
> └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
>
>
>
>  bix 3 4
>
> ┌───┬───┬───┬───┐
>
> │0 0│0 1│0 2│0 3│
>
> ├───┼───┼───┼───┤
>
> │1 0│1 1│1 2│1 3│
>
> ├───┼───┼───┼───┤
>
> │2 0│2 1│2 2│2 3│
>
> └───┴───┴───┴───┘
>
>
>  bix 2 3 4
>
> ┌─────┬─────┬─────┬─────┐
>
> │0 0 0│0 0 1│0 0 2│0 0 3│
>
> ├─────┼─────┼─────┼─────┤
>
> │0 1 0│0 1 1│0 1 2│0 1 3│
>
> ├─────┼─────┼─────┼─────┤
>
> │0 2 0│0 2 1│0 2 2│0 2 3│
>
> └─────┴─────┴─────┴─────┘
>
> ┌─────┬─────┬─────┬─────┐
>
> │1 0 0│1 0 1│1 0 2│1 0 3│
>
> ├─────┼─────┼─────┼─────┤
>
> │1 1 0│1 1 1│1 1 2│1 1 3│
>
> ├─────┼─────┼─────┼─────┤
>
> │1 2 0│1 2 1│1 2 2│1 2 3│
>
> └─────┴─────┴─────┴─────┘
>
----------------------------------------------------------------------
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