Inverse Where
3 posts
• Page 1 of 1
Inverse Where
18.0 introduced the inverse of Where, monadic ⍸⍣¯1. Thanks! As pointed out to me on Reddit (https://www.reddit.com/r/adventofcode/c ... ?context=3) it is useful for building grids out of coordinates:
Unfortunately it insists that its argument is sorted:
Can you please consider removing that restriction? I see no benefits and several disbenefits:
⍸⍣¯1⊢(1 2)(2 1)(3 3)
0 1 0
1 0 0
0 0 1
Unfortunately it insists that its argument is sorted:
⍸⍣¯1⊢(2 1)(1 2)(3 3)
DOMAIN ERROR
Can you please consider removing that restriction? I see no benefits and several disbenefits:
- It took me a long time to work out the reason for the DOMAIN ERROR, and ⎕DMX was no help.
- The workaround is to explicitly sort the argument, which takes programmer and CPU time: ⍸⍣¯1{(⊂⍋⍵)⌷⍵}(2 1)(1 2)(3 3)
- Checking that the argument is sorted must take up even more CPU time.
- jayfoad
- Posts: 5
- Joined: Wed May 29, 2019 1:51 pm
Re: Inverse Where
I believe that a reason for requiring that the argument x in ⍸⍣¯1⊢x be sorted, is that that ensures
x ←→ ⍸ ⍸⍣¯1 ⊢x.
x ←→ ⍸ ⍸⍣¯1 ⊢x.
- Roger|Dyalog
- Posts: 238
- Joined: Thu Jul 28, 2011 10:53 am
Re: Inverse Where
I would like to point out that a better way to create the grid from the coordinates, is the @ operator. For example:
For a vector:
That is, ⍸⍣¯1 does not necessarily get the original argument but @ does. Put another way, ⍸⍣¯1⊢x produces the correct grid only if x contains the maximum coordinate.
Likewise for a matrix:
For a vector:
b←(?10⍴2),4⍴0
b
0 1 0 1 0 0 1 0 1 0 0 0 0 0
⍸b
1 3 6 8
⍸⍣¯1 ⍸b
0 1 0 1 0 0 1 0 1
1@(⍸b)⊢14⍴0
0 1 0 1 0 0 1 0 1 0 0 0 0 0
b ≡ 1@(⍸b)⊢14⍴0
1
That is, ⍸⍣¯1 does not necessarily get the original argument but @ does. Put another way, ⍸⍣¯1⊢x produces the correct grid only if x contains the maximum coordinate.
Likewise for a matrix:
c←5 6↑?3 4⍴2
c
1 1 1 0 0 0
0 1 0 0 0 0
1 0 1 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0
⍸c
┌───┬───┬───┬───┬───┬───┬───┐
│0 0│0 1│0 2│1 1│2 0│2 2│2 3│
└───┴───┴───┴───┴───┴───┴───┘
⍸⍣¯1 ⍸ c
1 1 1 0
0 1 0 0
1 0 1 1
1@(⍸c)⊢5 6⍴0
1 0 0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
c ≡ 1@(⍸c)⊢5 6⍴0
1
- Roger|Dyalog
- Posts: 238
- Joined: Thu Jul 28, 2011 10:53 am
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group