I am using NumPy.
I defined a vector xwith NumPy and other variables with numeric values.
I will return a vector of ythe same length as x, but the values y[i]in this vector ymust be calculated from different formulas depending on the corresponding one x[i].
Can I do something clever with NumPy or do I need to iterate through a vector xand for each element to xdetermine whether it is x[i]more or less than a certain value and determine which formula to use for a particular element?
I think I could do something like
y[x > a] = 2*x+7
y[x <= a] = 3*x+9
return y
source
share