Question: I have a pair of 2-d arrays of the same size, source array and destination array. Source array also has an identically sized boolean array filled with a random mixture of True/False values. I want to copy over the source cells that correspond to "True" values in the boolean array into the equivalent locations in the destination array, overwriting those specific destination values.

There's got to be a better way to do this than by slowly for-looping my way across the entire source array, checking against the boolean array, and overwriting individual values in the destination.

[![Sample](https://i.stack.imgur.com/g6fcV.png)](https://i.stack.imgur.com/g6fcV.png)

Answer: 
This is one way.

```
import numpy as np

S = np.array([[65, 44, 77],
              [25, 22, 31],
              [14, 20, 63]])

B = np.array([[1, 0, 1],
              [0, 0, 1],
              [0, 1, 0]], dtype=bool)

D = np.array([[85, 10, 20],
              [15, 12, 32],
              [66, 28, 13]])

D[B] = S[B]

```

Result:

```
array([[65, 10, 77],
       [15, 12, 31],
       [66, 20, 13]])

```
No need of numpy. You can do this:

```
source_array, bool_array, destination_array = [65, 44, 77],["T", "F", "T"], [85, 10, 20]
bool_array = ["T", "F", "T"]
for index, value in enumerate(destination_array):
    if bool_array[index] == "T":
        destination_array[index] = source_array[index]
print (destination_array)

```

If you want to do the same thing on multiple arrays, simply place it inside a function:

```
def transfer(source_array, bool_array, destination_array):
    for index, value in enumerate(destination_array):
        if bool_array[index] == "T":
            destination_array[index] = source_array[index]
    return destination_array

```

Now call the function on all the lists you need.