I have two multi-dimensional numpy array. I would like to convert the entry in the second array to NaN, if the corresponding element in first is zero. Below is example to manually mimic the same: (Can this be done programmatically)
import numpy as np
a = np.random.rand(4,5)
a[0][0] = 0
a[1][0] = 0
a[1][1] = 0
b = np.random.rand(4,5)
b[0][0] = np.nan
b[1][0] = np.nan
b[1][1] = np.nan
Can we use masking here?
Write it like you say it:
b[a==0] = np.nan
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With