Assemble matrix when its shape is known