# Inserting a Small Array into a Big Array

Hello everyone!

I was consulting the message forum and looking at the documentation, but I’m still at a bit of a loss for how to do this.

I’d like to take a small Array2D of 4x4…and I’d like to insert it into a larger, separate Array, 40x40.

Generating the small array is easy.

``````~array = [[0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 1, 1], [0, 0, 0, 0]];
~array = Array2D.fromArray(4, 4, ~array.flatten);
``````

Generating a big, blank array is easy.

``````~bigArray = Array2D.new(40, 40);
``````

But I’m not sure what to do next. I tried the following, but I can tell something is wrong…

``````~array.do{|r, in1|
r.do{|c, in2|
in2.postln;
~bigArray.put(10+in1, 10+in2, c);
}};

``````

Anyway, thanks for the help!

It works if you use the method .rowsDo, as in:

``````(
~array = 1 ! 16;  // fill with 1's
~array = Array2D.fromArray(4, 4, ~array);

~bigArray = 0 ! 40.squared;   // fill with 0's
~bigArray = Array2D.fromArray(40, 40, ~bigArray);

// use rowsDo here:
~array.rowsDo{|r, in1|
r.do{|c, in2|
in2.postln;
~bigArray.put(10+in1, 10+in2, c);
}};
// print row by row to see it
~bigArray.rowsDo({arg r; r.postln;});
)
``````

Best,
Paul