Project 24: Weekend Checker Ufunc
Data Engineer
Builds on these lessons
Current Task
Objective
np.frompyfunc() turns a plain Python function into a ufunc, so it can be applied element-wise across a whole array.
Task: write an is_weekend function, turn it into a ufunc, and apply it to an array of day numbers.
index.py
import numpy as np
def is_weekend(day_num):
return day_num in (6, 7)
check_weekend = np.frompyfunc(is_weekend, 1, 1)
days = np.array([1, 2, 6, 7])
print(check_weekend(days))
* Hint: Correct characters turn green, incorrect ones turn red.
Live Preview
🖼️
Verify your code to see the preview