# Array 3D. How to give values to each cell?

Hi Everyone! I Need Your Help.
I´m a I’m a beginner.
How to loop through a 3d array? How to give values to each cell?

``````y = Array.fillND([3, 3, 3]);
y[0, 0 ,0] = 64; // [ 0, [ [ nil, nil, nil ], [ nil, nil, nil ], [ nil, nil, nil ] ], [ [ nil, nil, nil ], [ nil, nil, nil ], [ nil, nil, nil ] ] ] It´s akn error. I want my firts value was 64.

``````
``````(
y = Array.fillND([3, 3, 3]).debug("start y");
y = 64;
y.debug("new y");
)

// or visit every element (maybe there are even shorter notations...not sure)
(
y = Array.fillND([3, 3, 3]).debug("start y");
3.do {
|p|
3.do {
|q|
3.do {
|r|
y[p][q][r] = (2**p) + (3**q) + (5**r);
};
};
};
y.debug("new y");
)
``````

Those `fill`s also take a function as arg, evaluated at every array position with indices passed as arguments to the said function. So, e.g.

``````Array.fill3D(3, 3, 3, {|p,q,r| (2**p) + (3**q) + (5**r)})
Array.fillND([3, 3, 3], {|p,q,r| (2**p) + (3**q) + (5**r)})
``````

Somewhat more obscurely

``````{|p,q,r| (2**p) + (3**q) + (5**r)} dup: [3, 3, 3]
{|p,q,r| (2**p) + (3**q) + (5**r)} ! [3, 3, 3]
``````
1 Like

Hi,

``````y = 64;

y.flatten.do { |x| x.postln }
``````

Thank you Very Much!!! 