my question is if there is an easy way to copy non zero values from one numpy 3d array to another. I wouldn't like to create 3 for loops for that...
Let's say I have an array a:
a = np.array([ [ [1,2,3], [4,5,6]],[[7,8,9], [10,11,12] ] ])
# to visualize it better:
# a = np.array([
# [
# [1,2,3],
# [4,5,6]
# ],
# [
# [7,8,9],
# [10,11,12]
# ]
# ])
#
then there is an array b:
b = np.array([ [[3,0,9], [0,0,0]], [[0,0,0], [45,46,47]] ])
# to visualize it better:
# b = np.array([
# [
# [3,0,9],
# [0,0,0]
# ],
# [
# [0,0,0],
# [45,46,47]
# ]
# ])
#
And I would like to merge those arrays to receive non-zero elements from b and other elements from a (these elements that are 0s in b) SO the output would look like:
#
# np.array([
# [
# [3,2,9],
# [4,5,6]
# ],
# [
# [7,8,9],
# [45,46,47]
# ]
# ])
#
It doesn't have to be numpy, it can be openCV, but still I would like to know how to achieve this.