I’ve been using Julia for the first time for a project, and I’ve been running into issues with using list comprehensions to make multidimensional arrays when I have a vector-valued function. As a toy example, I could have a function f(x,y)
that outputs a 2 x 3 matrix, and I’d like to run this function on many (x,y)
pairs. So far, I’ve been writing list comprehensions like,
[f(x,y) for x in 1:4, y in 1:5]
However, this produces a 4 x 5 matrix of 2D arrays, whereas I want a 2 x 3 x 4 x 5 4D array. I’ve read about some ways to turn the result of this list comprehension into a 4D array, but they all seem quite unwieldy in the case of multidimensional list comprehensions, especially when I’m doing this many times in my code. Is there a clean way to convert this into a 4D array, or even better, a direct method to create the 4D array straight away? Thank you!
(Edit: replaced matrix with 4D array)