I am curious whether anyone has written a Stan function that converts an array of arbitrary dimensions to a “long” matrix whose first D columns indicate the D indices of the array and whose D+1th column indicates the value in each cell of the array. Figure 16.1 on p. 230 of the Stan manual (version 2.17.0) illustrates the conversion I am thinking of (though it also drops missing elements, which is not essential for my purposes). Obviously this conversion is easy to do in R with a function like reshape2::melt, but ideally I would also be able to do it within Stan as well. My sense from reading Stan forums is that there has been some demand for such a function in the past, but I wasn’t able to locate any workable solutions. Any help would be appreciated. Thanks!