How to have vectorize calculation between a 1D and 2D numpy array with if conditions
问题 I have a calculation using a 1D and a 2D numpy array. It has two levels of if -conditions. I was able to use np.where to avoid one if -statement and further use the slow list comprehension to iterate through each row. Ideally, I would like to vectorize the whole calculation process. Is it possible? Here is my code: import numpy as np r_base = np.linspace(0, 4, 5) np.random.seed(0) r_mat = np.array([r_base * np.random.uniform(0.9, 1.1, 5), r_base * np.random.uniform(0.9, 1.1, 5), r_base * np