,.+ ??
5 posts
• Page 1 of 1
,.+ ??
Book : Mastering Dyalog APL. Page 405 5.4 Inner Product.
----------------------------------------------------------
a : 2 4 1
1 3 5
b : 3 0 2 5
1 7 7 2
6 0 4 2
a ,.+ b gives: 5 5 7 2 11 1 4 11 5 7 6 3
4 4 11 1 10 5 3 10 9 6 5 7
a +., b gives: 7 10 7 7 7 13 7 9
9 10 9 7 9 13 9 9
Too bad that this book does not explains how it comes to such results.
Could anyone explains this to me ?
Thanks
Henk.
Att.Picture is maybe more clear:
----------------------------------------------------------
a : 2 4 1
1 3 5
b : 3 0 2 5
1 7 7 2
6 0 4 2
a ,.+ b gives: 5 5 7 2 11 1 4 11 5 7 6 3
4 4 11 1 10 5 3 10 9 6 5 7
a +., b gives: 7 10 7 7 7 13 7 9
9 10 9 7 9 13 9 9
Too bad that this book does not explains how it comes to such results.
Could anyone explains this to me ?
Thanks
Henk.
Att.Picture is maybe more clear:
- Attachments
-
- P405.JPG (9.33 KiB) Viewed 7336 times
- hbarkhof
- Posts: 44
- Joined: Mon Apr 09, 2018 8:37 am
Re: ,.+ ??
The string a,.+b, firsts adds a to b and then ravels the results.
Lets first add 0 to b and see the result:
now lets add 100 1000 10000 to b and see the result:
now lets add the first row of a to b and see the result:
Now lets add just the second row of a to b and see the result:
Now lets add a to b and see the final result:
Does this help?
- Code: Select all
⎕se.DISPLAY a
┌→────┐
↓2 4 1│
│1 3 5│
└~────┘
⎕se.DISPLAY b
┌→──────┐
↓3 0 2 5│
│1 7 7 2│
│6 0 4 2│
└~──────┘
Lets first add 0 to b and see the result:
- Code: Select all
⎕se.DISPLAY 0 ,.+ b
┌→────────────────────────────────┐
│ ┌→────┐ ┌→────┐ ┌→────┐ ┌→────┐ │
│ │3 1 6│ │0 7 0│ │2 7 4│ │5 2 2│ │
│ └~────┘ └~────┘ └~────┘ └~────┘ │
└∊────────────────────────────────┘
now lets add 100 1000 10000 to b and see the result:
- Code: Select all
⎕SE.DISPLAY 100 1000 10000,.+b
┌→────────────────────────────────────────────────────────────────────┐
│ ┌→─────────────┐ ┌→─────────────┐ ┌→─────────────┐ ┌→─────────────┐ │
│ │103 1001 10006│ │100 1007 10000│ │102 1007 10004│ │105 1002 10002│ │
│ └~─────────────┘ └~─────────────┘ └~─────────────┘ └~─────────────┘ │
└∊────────────────────────────────────────────────────────────────────┘
now lets add the first row of a to b and see the result:
- Code: Select all
⎕SE.DISPLAY 2 4 1,.+b
┌→──────────────────────────────────┐
│ ┌→────┐ ┌→─────┐ ┌→─────┐ ┌→────┐ │
│ │5 5 7│ │2 11 1│ │4 11 5│ │7 6 3│ │
│ └~────┘ └~─────┘ └~─────┘ └~────┘ │
└∊──────────────────────────────────┘
Now lets add just the second row of a to b and see the result:
- Code: Select all
⎕SE.DISPLAY 1 3 5,.+b
┌→───────────────────────────────────┐
│ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→────┐ │
│ │4 4 11│ │1 10 5│ │3 10 9│ │6 5 7│ │
│ └~─────┘ └~─────┘ └~─────┘ └~────┘ │
└∊───────────────────────────────────┘
Now lets add a to b and see the final result:
- Code: Select all
⎕SE.DISPLAY a,.+b
┌→───────────────────────────────────┐
↓ ┌→────┐ ┌→─────┐ ┌→─────┐ ┌→────┐ │
│ │5 5 7│ │2 11 1│ │4 11 5│ │7 6 3│ │
│ └~────┘ └~─────┘ └~─────┘ └~────┘ │
│ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→────┐ │
│ │4 4 11│ │1 10 5│ │3 10 9│ │6 5 7│ │
│ └~─────┘ └~─────┘ └~─────┘ └~────┘ │
└∊───────────────────────────────────┘
Does this help?
Ray Cannon
Please excuse any smelling pisstakes.
Please excuse any smelling pisstakes.
-
ray - Posts: 221
- Joined: Wed Feb 24, 2010 12:24 am
- Location: Blackwater, Camberley. UK
Re: ,.+ ??
It sure does help completely , Ray !
Such explanation should be in the book , imho.
Thanks again !
Such explanation should be in the book , imho.
Thanks again !
- hbarkhof
- Posts: 44
- Joined: Mon Apr 09, 2018 8:37 am
Re: ,.+ ??
You might also like to experiment with the tc operator in the dfns workspace:
Another of the invaluable tools contained in the dfns workspace !
a ,tc.+ b
5 , 7 => 5 7
5 , 5 7 => 5 5 7
11 , 1 => 11 1
2 , 11 1 => 2 11 1
11 , 5 => 11 5
4 , 11 5 => 4 11 5
6 , 3 => 6 3
7 , 6 3 => 7 6 3
4 , 11 => 4 11
4 , 4 11 => 4 4 11
10 , 5 => 10 5
1 , 10 5 => 1 10 5
10 , 9 => 10 9
3 , 10 9 => 3 10 9
5 , 7 => 5 7
6 , 5 7 => 6 5 7
5 5 7 2 11 1 4 11 5 7 6 3
4 4 11 1 10 5 3 10 9 6 5 7
Another of the invaluable tools contained in the dfns workspace !
-
AndyS|Dyalog - Posts: 257
- Joined: Tue May 12, 2009 6:06 pm
Re: ,.+ ??
a
2 4 1
1 3 5
b
3 0 2 5
1 7 7 2
6 0 4 2
a +., b
┌────┬───┬────┬───┐
│7 10│7 7│7 13│7 9│
├────┼───┼────┼───┤
│9 10│9 7│9 13│9 9│
└────┴───┴────┴───┘
a,.+ b
┌──────┬──────┬──────┬─────┐
│5 5 7 │2 11 1│4 11 5│7 6 3│
├──────┼──────┼──────┼─────┤
│4 4 11│1 10 5│3 10 9│6 5 7│
└──────┴──────┴──────┴─────┘
For "weird" inner product combinations, it is helpful to look at the general definition:
X←{↑ ⍺⍺/¨ (↓⍺)∘.(⍵⍵¨) ↓[⎕IO]⍵}
(a +., b) ≡ a +X, b
1
(a ,.+ b) ≡ a ,X+ b
1
With the general definition in hand, you can then examine the intermediate steps.
It's helpful to turn boxing on:
]box on
ea←↓a
ea
┌─────┬─────┐
│2 4 1│1 3 5│
└─────┴─────┘
eb←↓[⎕io] b
eb
┌─────┬─────┬─────┬─────┐
│3 1 6│0 7 0│2 7 4│5 2 2│
└─────┴─────┴─────┴─────┘
Looking at the subexpressions in each case. For +.,
ea ∘.(,¨) eb
┌─────────────┬─────────────┬─────────────┬─────────────┐
│┌───┬───┬───┐│┌───┬───┬───┐│┌───┬───┬───┐│┌───┬───┬───┐│
││2 3│4 1│1 6│││2 0│4 7│1 0│││2 2│4 7│1 4│││2 5│4 2│1 2││
│└───┴───┴───┘│└───┴───┴───┘│└───┴───┴───┘│└───┴───┴───┘│
├─────────────┼─────────────┼─────────────┼─────────────┤
│┌───┬───┬───┐│┌───┬───┬───┐│┌───┬───┬───┐│┌───┬───┬───┐│
││1 3│3 1│5 6│││1 0│3 7│5 0│││1 2│3 7│5 4│││1 5│3 2│5 2││
│└───┴───┴───┘│└───┴───┴───┘│└───┴───┴───┘│└───┴───┴───┘│
└─────────────┴─────────────┴─────────────┴─────────────┘
+/¨ ea ∘.(,¨) eb
┌──────┬─────┬──────┬─────┐
│┌────┐│┌───┐│┌────┐│┌───┐│
││7 10│││7 7│││7 13│││7 9││
│└────┘│└───┘│└────┘│└───┘│
├──────┼─────┼──────┼─────┤
│┌────┐│┌───┐│┌────┐│┌───┐│
││9 10│││9 7│││9 13│││9 9││
│└────┘│└───┘│└────┘│└───┘│
└──────┴─────┴──────┴─────┘
↑ +/¨ ea ∘.(,¨) eb
┌────┬───┬────┬───┐
│7 10│7 7│7 13│7 9│
├────┼───┼────┼───┤
│9 10│9 7│9 13│9 9│
└────┴───┴────┴───┘
For ,.+
ea ∘.(+¨) eb
┌──────┬──────┬──────┬─────┐
│5 5 7 │2 11 1│4 11 5│7 6 3│
├──────┼──────┼──────┼─────┤
│4 4 11│1 10 5│3 10 9│6 5 7│
└──────┴──────┴──────┴─────┘
,/¨ ea ∘.(+¨) eb
┌────────┬────────┬────────┬───────┐
│┌─────┐ │┌──────┐│┌──────┐│┌─────┐│
││5 5 7│ ││2 11 1│││4 11 5│││7 6 3││
│└─────┘ │└──────┘│└──────┘│└─────┘│
├────────┼────────┼────────┼───────┤
│┌──────┐│┌──────┐│┌──────┐│┌─────┐│
││4 4 11│││1 10 5│││3 10 9│││6 5 7││
│└──────┘│└──────┘│└──────┘│└─────┘│
└────────┴────────┴────────┴───────┘
↑ ,/¨ ea ∘.(+¨) eb
┌──────┬──────┬──────┬─────┐
│5 5 7 │2 11 1│4 11 5│7 6 3│
├──────┼──────┼──────┼─────┤
│4 4 11│1 10 5│3 10 9│6 5 7│
└──────┴──────┴──────┴─────┘
- Roger|Dyalog
- Posts: 238
- Joined: Thu Jul 28, 2011 10:53 am
5 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