# How to access row of a 6 dimensional tensor fast?

I have a data set in 2D array form

data =
{{0.712828, 0.214808, 0.191034, 0.378026, 0.623859},
{0.622851, 0.356256, 0.766421, 0.431682, 0.260577},
{0.828761, 0.953634, 0.297046, 0.505364, 0.108341},
{0.541451, 0.481219, 0.202882, 0.158772, 0.700832}};


Each row of the data has distinctive feature. Based on these features, I have put them in 6 dimensional tensor. I tried following two methods

Do[
Do[
storeData[[m[i], n[i], p[i], q[i], r[i], j]] = data[[i, j]];
, {j, 1, Length[data[[1]]]}];
, {i, 1, Length[data]}];


and

Do[
storeData[[m[i], n[i], p[i], q[i], r[i]]] = data[[i]];
, {i, 1, Length[data]}];


m[i], n[i] etc. are indices of the tensor, The _[i] indicates, the m, n etc. are functions of i; i.e. they are to be determined using the distinctive features of the rows of the data. Both these methods are too time consuming (second method is somewhat faster, however it's lowering the length of the row of the dataStore tensor from what I allocated, initially).

I need a method, which can do this task swiftly. The problem is, I'm, at present, reading through all the first 5 dimensions for every iteration of the second loop, even though the corresponding block is known after the first iteration of the 2nd loop.

Is there a way to figure out the memory location after j=1 iteration and use it for all subsequent j values; the way a C++ pointer stores the memory address?

• This question is unclear. Also, without storeData, m, n etc. definitions, it’s impossible to run your code and replicate the behavior you observed. Jan 28, 2023 at 1:22
• How large is your actual data? Jan 28, 2023 at 1:33
• @lericr; The data length(i) is 1000 and width(j) is 40. Storing process needs to be completed under 1 milli seconds. Presently it's taking few 10's of milli seconds. Jan 28, 2023 at 1:38
• And are you using a SparseArray for your dataStore? Jan 28, 2023 at 1:38
• initially I thought of using NumericArray. But I couldn't Compile. So I'm using standard array. dataStore is a global variable Jan 28, 2023 at 1:41