Hi,

for the following nested vector the Selective Assigments do not work properly:
/
⍝ Matrix A is being repeated 3 times in B.
⍝ Matrix A has a skalar and an empty vector.
⍝ Those items have to be replaced.
/*     A←2 2⍴ 'A' 'abc' (2 2⍴'qwert') ' '
     B←3⍴⊂A
     8 ⎕CR B*
┌→─────────────────────────────────────┐
│┌→─────────┐ ┌→─────────┐ ┌→─────────┐│
│↓A    ┌→──┐│ ↓A    ┌→──┐│ ↓A    ┌→──┐││
││     │abc││ │     │abc││ │     │abc│││
││     └───┘│ │     └───┘│ │     └───┘││
││          │ │          │ │          ││
││┌→─┐      │ │┌→─┐      │ │┌→─┐      ││
││↓qw│      │ │↓qw│      │ │↓qw│      ││
│││er│      │ ││er│      │ ││er│      ││
││└──┘      │ │└──┘      │ │└──┘      ││
│└ϵ─────────┘ └ϵ─────────┘ └ϵ─────────┘│
└ϵϵ────────────────────────────────────┘

⍝/Identify places with scalar or '' (use depth = 0)/
*8 ⎕CR (0=,¨≡¨¨B) *
┌→────────────────────────────┐
│┌→──────┐ ┌→──────┐ ┌→──────┐│
││1 0 0 1│ │1 0 0 1│ │1 0 0 1││
│└───────┘ └───────┘ └───────┘│
└ϵ────────────────────────────┘

/⍝ Show affected elements ( 'A' and '')
⍝ There is one vector for each "A-matrix" in B /
//*    8 ⎕CR ((0=,¨≡¨¨B)/¨,¨B)*
┌→─────────────┐
│┌→─┐ ┌→─┐ ┌→─┐│
││A │ │A │ │A ││
│└──┘ └──┘ └──┘│
└ϵ─────────────┘

/⍝ Plain test, Assign the selected elements to the selection of B/
*((0=,¨≡¨¨B)/¨,¨B)←((0=,¨≡¨¨B)/¨,¨B)**
     8 ⎕CR B*
┌→─────────────────────────────────────┐
│┌→─────────┐ ┌→─────────┐ ┌→─────────┐│
│↓┌→─┐ ┌→──┐│ ↓┌→─┐ ┌→──┐│ ↓┌→─┐ ┌→──┐││
│││A │ │abc││ ││A │ │abc││ ││A │ │abc│││
││└──┘ └───┘│ │└──┘ └───┘│ │└──┘ └───┘││
││          │ │          │ │          ││
││┌→─┐ ┌→─┐ │ │┌→─┐ ┌→─┐ │ │┌→─┐ ┌→─┐ ││
││↓qw│ │A │ │ │↓qw│ │A │ │ │↓qw│ │A │ ││
│││er│ └──┘ │ ││er│ └──┘ │ ││er│ └──┘ ││
││└──┘      │ │└──┘      │ │└──┘      ││
│└ϵ─────────┘ └ϵ─────────┘ └ϵ─────────┘│
└ϵϵ────────────────────────────────────┘

/⍝ The elements of interest in B now have a depth of 2 !!!/
*8 ⎕CR **(⊂⊂,2)≡¨¨ (⍴¨¨B)*
┌→────────────────┐
│┌→──┐ ┌→──┐ ┌→──┐│
│↓1 0│ ↓1 0│ ↓1 0││
││0 1│ │0 1│ │0 1││
│└───┘ └───┘ └───┘│
└ϵ────────────────┘

/
//⍝Instead of the expected /*⍬*//
*B←3⍴⊂A*
***8 ⎕CR **(⊂⊂,⍬ )≡¨¨ (⍴¨¨B)**
*┌→────────────────┐
│┌→──┐ ┌→──┐ ┌→──┐│
│↓1 0│ ↓1 0│ ↓1 0││
││0 1│ │0 1│ │0 1││
│└───┘ └───┘ └───┘│
└ϵ────────────────┘


/⍝ The Selective Assignment actually repeats only one element /
*B←3⍴⊂A*
* ⍴((0=,¨≡¨¨B)/¨,¨B)**
*3

*((0=,¨≡¨¨B)/¨,¨B)←'XY' 'CV' 'NM'*
*  8 ⎕CR B***
┌→─────────────────────────────────────┐
│┌→─────────┐ ┌→─────────┐ ┌→─────────┐│
│↓┌→─┐ ┌→──┐│ ↓┌→─┐ ┌→──┐│ ↓┌→─┐ ┌→──┐││
│││NM│ │abc││ ││NM│ │abc││ ││NM│ │abc│││
││└──┘ └───┘│ │└──┘ └───┘│ │└──┘ └───┘││
││          │ │          │ │          ││
││┌→─┐ ┌→─┐ │ │┌→─┐ ┌→─┐ │ │┌→─┐ ┌→─┐ ││
││↓qw│ │NM│ │ │↓qw│ │NM│ │ │↓qw│ │NM│ ││
│││er│ └──┘ │ ││er│ └──┘ │ ││er│ └──┘ ││
││└──┘      │ │└──┘      │ │└──┘      ││
│└ϵ─────────┘ └ϵ─────────┘ └ϵ─────────┘│
└ϵϵ────────────────────────────────────┘

Best regards
Hans-Peter

Reply via email to