How to efficently copy the non-zero elements in an array to another array