How do I access a specific element in a vector of vectors clojure

clojure, vector

Solution

Vectors are associative, so you can use `get-in` to access nested vectors, e.g. matrices, by coordinates.

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

(get-in matrix [1 1])
;=> 5

Problem

If I have a vector defined as ``` (def matrix [[1 2 3][4 5 6]]) ``` How in clojure do I access a random element in a vector of vectors? I keep seeing people say online that one of the benefits to using a vector over a list is that you get random access instead of having to recurse through a list but I haven't been able to find the function that allows me to do this. I'm used to in c++ where I could do matrix[1][1] and it would return the second element of the second vector. Am I stuck having to loop one element at a time through my vector or is there an easier way to access specific elements?

Original source