it fixes the issue If you want not just to read the values but also set them in the same order as foreach traverses the array, you can use the following general indexer class: code :
public class ArrayIndexer
{
readonly int totalLength;
readonly int lastIndexLength;
readonly int[] lengths;
readonly int[] lowerBounds;
int current;
readonly int[] currentZeroBased;
public ArrayIndexer(int[] lengths, int[] lowerBounds)
{
lastIndexLength = lengths[lengths.Length  1];
totalLength = lengths[0];
for (int i = 1; i < lengths.Length; i++)
{
totalLength *= lengths[i];
}
this.lengths = lengths;
this.lowerBounds = lowerBounds;
currentZeroBased = new int[lengths.Length];
current = 1;
}
public bool MoveNext()
{
current++;
if (current != 0)
{
int currLastIndex = current % lastIndexLength;
currentZeroBased[currentZeroBased.Length  1] = currLastIndex;
if (currLastIndex == 0)
{
for (int i = currentZeroBased.Length  2; i >= 0; i)
{
currentZeroBased[i]++;
if (currentZeroBased[i] != lengths[i])
break;
currentZeroBased[i] = 0;
}
}
}
return current < totalLength;
}
public int[] Current
{
get
{
int[] result = new int[currentZeroBased.Length];
for (int i = 0; i < result.Length; i++)
{
result[i] = currentZeroBased[i] + lowerBounds[i];
}
return result;
}
}
}
int[,] myArray = new int[2, 2];
ArrayIndexer arrayIndexer = new ArrayIndexer(new[] {2, 2}, new[] {0, 0});
int i = 0;
while (arrayIndexer.MoveNext())
{
myArray.SetValue(++i, arrayIndexer.Current);
}
Share :

Finding dimensional index in a multidimensional array in R
By : Omar Akash
Date : March 29 2020, 07:55 AM
wish of those help @James's answer is better, but I think the narrow answer to your question (multidimensional equivalent of row()/col()) is slice.index ... code :
M< array(dim=c(3,3,3))
slice.index(M,1)/10+slice.index(M,2)^2+sqrt(slice.index(M,3))
d < do.call(expand.grid,lapply(dim(M),seq)) ## create data.frame of indices
v < with(d,Var1/10+Var2^2+sqrt(Var3)) ## default names Var1, ... Varn
dim(v) < dim(M) ## reshape into array

Undefined index when accessing multidimensional array
By : Tom
Date : March 29 2020, 07:55 AM
wish of those help $item = $company['product']; // throws undefined index product In here you are passing the wrong key use $item = $company['products'];

Accessing 3dimensional matrix by a 2dimensional index in matlab/octave
By : Peter Fisera
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I have a 3 dimensional matrix (3rd dimension represents multiple copies of an M x N grayscale image). , One approach  code :
%// Get size of 3D input array
[m,n,~] = size(test);
%// Calculate 2D starting, offset & finally actual indices array
start_idx = bsxfun(@plus,[1:m]',[0:n1]*m); %//'
offset_idx = m*n*(max_ix1);
actual_idx = start_idx + offset_idx;
%// Index into 3D input array to extract specific elements, for desired output
max_val = test(actual_idx)
[m,n,~] = size(test);
max_val = test( bsxfun(@plus,[1:m]',[0:n1]*m) + m*n*(max_ix1) )
test(:,:,1) =
12 66 75 98
65 75 24 87
33 59 74 9
test(:,:,2) =
37 60 21 21
37 79 9 39
69 37 78 56
test(:,:,3) =
23 16 30 10
65 79 24 41
49 11 54 11
test(:,:,4) =
12 61 70 66
79 97 76 11
30 44 44 94
max_ix =
1 2 2 2
2 4 1 2
4 2 3 3
max_val =
12 60 21 21
37 97 24 39
30 37 54 11

How to create single dimensional, two dimensional,three dimensional as well as multi dimensional array using C#?
By : Bilal Bhatti
Date : March 29 2020, 07:55 AM

Accessing multidimensional array using a onedimensional index in R
By : MK15
Date : March 29 2020, 07:55 AM
Any of those help With R, you have a choice of indexing with arrays and matrices. You can use the dimensional indexing or you can use vector indexng. Just use: code :
myArray[123:(123+11) ]

