You can create a mask to selectively operate on items within your array. It is easier to visualize with 2d arrays, so for example sake:
import numpy as np
a = np.random.randint(0, 10, (5, 4))
b = np.random.randint(0, 10, (5, 4))
Let's see what a and b look like.
In [317]: a
Out[317]:
array([[6, 0, 4, 0],
[1, 9, 1, 6],
[7, 2, 5, 0],
[8, 3, 5, 0],
[1, 8, 1, 6]])
In [318]: b
Out[318]:
array([[1, 3, 2, 1],
[9, 1, 9, 4],
[9, 4, 5, 5],
[6, 0, 6, 4],
[5, 1, 1, 2]])
Suppose we want to select locations where a==0 and b==3, we build an index (mask).
idx = (a==0) & (b==3)
How does idx look?
In [320]: idx
Out[320]:
array([[False, True, False, False],
[False, False, False, False],
[False, False, False, False],
[False, False, False, False],
[False, False, False, False]])
Now, if you want to operate on array a where a==0 and b==3 (suppose we want to make the a value equal the b value:
a[idx] = b[idx]
Now what does a look like?
In [322]: a
Out[322]:
array([[6, 3, 4, 0],
[1, 9, 1, 6],
[7, 2, 5, 0],
[8, 3, 5, 0],
[1, 8, 1, 6]])
With this knowledge in hand, you can apply the same method to 3d arrays (though harder to visualize).
# identify pixels that are NOT black (i.e. not equal to 0 0 0)
idx = (image1[:, :, 0] == 0) & (image1[:, :, 1] == 0) & (image1[:, :, 2] == 0)
image1[~idx] = image2[~idx]