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.@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
)
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
)
Awesome, that worked! Thank you :)
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]])
@allaboutthatmace1789 srange
navigates to a single subsequence, ALL
navigates to each element
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?