specter

Latest version: 1.1.3
2020-05-06T15:29:26.022300Z

Hi everyone! I am trying to navigate a 4D array and would like to get all the indicies (the path to get there). How do I do that? So far I have the following

(transform [ALL (collect-one INDEXED-VALS FIRST)
              ALL (collect-one INDEXED-VALS FIRST)
              ALL (collect-one INDEXED-VALS FIRST)
              ALL (collect-one INDEXED-VALS)]
             (fn [d1 d2 d3 d4 item]
                 ...))
             4d-array))
But I don’t quite understand how the collect function works? Can anyone please help me? 🙂 Thank you.

nathanmarz 2020-05-06T19:54:54.023100Z

@ragonedk you want something more like:

(transform [INDEXED-VALS
            (collect-one FIRST)
            LAST
            INDEXED-VALS
            (collect-one FIRST)
            LAST
            INDEXED-VALS
            (collect-one FIRST)
            LAST
            INDEXED-VALS
            (collect-one FIRST)
            LAST
            ]
  (fn [d1 d2 d3 d4 item]
    )
  4d-arr
  )

nathanmarz 2020-05-06T19:55:57.023400Z

you can shorten that like this:

(def ALL-AND-COLLECT-INDEX (path INDEXED-VALS (collect-one FIRST) LAST))

(transform [ALL-AND-COLLECT-INDEX
            ALL-AND-COLLECT-INDEX
            ALL-AND-COLLECT-INDEX
            ALL-AND-COLLECT-INDEX]
  (fn [d1 d2 d3 d4 item]
    )
  4d-arr
  )

2020-05-06T19:57:15.024100Z

Awesome, that worked! Thank you :)

Joe 2020-05-06T22:12:14.029400Z

Hello, I have a 9x9 matrix using nested vectors, and I want to pull out the top left 'subsquare' , i.e. elements at [0-2, 0-2]. I got the results I wanted with (select [(srange 0 3) ALL (srange 0 3)] data) , but I don't understand the need for the ALL inbetween the two sranges. I was thinking the first srange would grab the first 3 vectors, and the second would grab the first 3 elements from each of them - what's the concept I'm missing that means you need the ALL in the middle? Here's the data:

(def data
  [[5 3 0 0 7 0 0 0 0]
   [6 0 0 1 9 5 0 0 0]
   [0 9 8 0 0 0 0 6 0]
   [8 0 0 0 6 0 0 0 3]
   [4 0 0 8 0 3 0 0 1]
   [7 0 0 0 2 0 0 0 6]
   [0 6 0 0 0 0 2 8 0]
   [0 0 0 4 1 9 0 0 5]
   [0 0 0 0 8 0 0 7 9]]) 

nathanmarz 2020-05-06T22:37:05.029900Z

@allaboutthatmace1789 srange navigates to a single subsequence, ALL navigates to each element

Joe 2020-05-06T22:52:22.033400Z

So the first srange gets to [[1 2 3 ,,,] [1 2 3 ,,,] [1 2 3 ,,,]], you need the ALL to tell it grab every element [1 2 3 ,,,] [1 2 3 ,,,] [1 2 3 ,,,], then for each of those elements the second srange gets the subseq of first 3 elements [1 2 3] [1 2 3] [1 2 3] - then wraps everything back up again?