I tried to draw (a consistent, not the most efficient way to do this, but my question is rather using a decorator) the following function
@np.vectorize
def diff_if_bigger(x, y):
return y - x if y > x else 0
x = np.array([5.6, 7.0])
y = 8
diff_if_bigger(x, y)
EDIT : after restarting IPython, the output was ok.
Can anyone explain why the result diff_if_biggergot tansformed into an array np.int, even if the first argument of x here is aray of np.float, as opposed to in doc ????
Now I want to force a float, so I did it
@np.vectorize('np.float')
def diff_if_bigger(x, y):
return y - x if y > x else 0
@np.vectorize(otypes='np.float')
def diff_if_bigger(x, y):
return y - x if y > x else 0
@np.vectorize(otypes=[np.float])
def diff_if_bigger(x, y):
return y - x if y > x else 0
By the way, even this
vec_diff = np.vectorize(diff_if_bigger, otypes=[np.float])
does not work!!! So what is going on?
EDIT : Actually the latter worked after restarting IPython.
So, after my previous two changes, my question is now twofold:
1 np.vectorize ?
2 IPython?