Replacing for loops with function call inside with broadcasting/vectorized solution
问题 Problem: When using broadcasting, rather than broadcasting scalars to match the arrays, the vectorized function is instead, for some reason, shrinking the arrays to scalars. MWE: Below is a MWE. It contains a double for loop. I am having trouble writing faster code that does not use the for loops, but instead, uses broadcasting/vectorized numpy. import numpy as np def OneD(x, y, z): ret = np.exp(x)**(y+1) / (z+1) return ret def ThreeD(a,b,c): value = OneD(a[0],b[0], c) value *= OneD(a[1],b[1]