Note
Numpy (15) 본문
728x90
How to make a python function that handles scalars to work on numpy arrays?
def maxx(x, y):
"""Get the maximum of two items"""
if x >= y:
return x
else:
return y
pair_max = np.vectorize(maxx, otypes=[float])
a = np.array([5, 7, 9, 8, 6, 4, 5])
b = np.array([6, 3, 4, 8, 9, 7, 1])
pair_max(a, b)
# output
array([ 6., 7., 9., 8., 9., 7., 5.])
'Numpy' 카테고리의 다른 글
Numpy (17) (0) | 2022.08.08 |
---|---|
Numpy (16) (0) | 2022.08.07 |
Numpy (14) (0) | 2022.08.05 |
Numpy (13) (0) | 2022.08.03 |
Numpy (12) (0) | 2022.08.02 |
Comments