## Access same row/column in each array in nested arrays

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

### Access same row/column in each array in nested arrays

Is there a way to multiply or add a scalar to the same row or column in each array of a nested array without a loop? For example I would like to multiply all the values in the 2nd column (or row) of each array by 2 for the sample nested array below.

`      ┌→─────────────────────────────────┐│ ┌→───────┐ ┌→───────┐ ┌→───────┐ ││ ↓ 1  2  3│ ↓ 4  8 10│ ↓ 9 46 30│ ││ │ 4  5  6│ │ 3 16 10│ │65 13 67│ ││ │ 7  8  9│ │ 2 16 19│ │55 50  3│ ││ │10 11 12│ │ 4  9  4│ └~───────┘ ││ └~───────┘ │13  6 10│            ││            └~───────┘            │└∊─────────────────────────────────┘`
KamakaniKing

Posts: 8
Joined: Thu Mar 25, 2021 8:06 pm

### Re: Access same row/column in each array in nested arrays

I gave up copying your numbers and just did
`      zz←(4 3)(5 3)(3 3)⍴¨⊂⍳15`
so:
`      zz 0  1  2   0  1  2  0 1 2  3  4  5   3  4  5  3 4 5  6  7  8   6  7  8  6 7 8  9 10 11   9 10 11                  12 13 14⍝ twice the 2th row of each matrix      2×@2¨zz  0  1  2   0  1  2   0  1  2   3  4  5   3  4  5   3  4  5  12 14 16  12 14 16  12 14 16   9 10 11   9 10 11                      12 13 14           ⍝ twice the 2th item of each row of each matrix      2×@2⍤1¨zz 0  1  4   0  1  4  0 1  4  3  4 10   3  4 10  3 4 10  6  7 16   6  7 16  6 7 16  9 10 22   9 10 22                   12 13 28`

Phil Last

Posts: 571
Joined: Thu Jun 18, 2009 6:29 pm

### Re: Access same row/column in each array in nested arrays

Phil - Thx! Perfect. Sorry for the lousy sample array....
KamakaniKing

Posts: 8
Joined: Thu Mar 25, 2021 8:06 pm

### Re: Access same row/column in each array in nested arrays

Phil - Assuming the nested arrays (zz) are all (n by 2) matrices, is there a way to multiply each by a 2x2 rotation matrix (r): zz +.× r
KamakaniKing

Posts: 8
Joined: Thu Mar 25, 2021 8:06 pm

### Re: Access same row/column in each array in nested arrays

You can just put the +.× under the each ¨ operator.

If r is equally a vector of different 2 by 2 matrices then
`      zz +.× ¨ r`
If there is just a single matrix then enclose it
`      zz +.× ¨ ⊂r`
There might be a more efficient way by restructuring the data using more dimensions but the above should work.

Phil Last

Posts: 571
Joined: Thu Jun 18, 2009 6:29 pm

### Re: Access same row/column in each array in nested arrays

Phil - Thx! This works great!
KamakaniKing

Posts: 8
Joined: Thu Mar 25, 2021 8:06 pm