Recall & Review
beginner
What does
np.frompyfunc() do in NumPy?It creates a universal function (ufunc) from a regular Python function, allowing element-wise operations on NumPy arrays.
Click to reveal answer
beginner
What are the required arguments for
np.frompyfunc()?You need to provide the Python function, the number of input arguments it takes, and the number of outputs it returns.
Click to reveal answer
intermediate
Why use
np.frompyfunc() instead of a simple Python loop?Because ufuncs created by
np.frompyfunc() can apply the function element-wise on arrays efficiently and support broadcasting.Click to reveal answer
intermediate
What is the difference between
np.vectorize() and np.frompyfunc()?np.vectorize() is a convenience wrapper that is slower and returns arrays with native dtypes, while np.frompyfunc() creates a true ufunc that returns object arrays and supports multiple outputs.Click to reveal answer
beginner
What type of array does a ufunc created by
np.frompyfunc() return?It returns an array of type
object, because the ufunc wraps a Python function that can return any Python object.Click to reveal answer
What does the second argument of
np.frompyfunc(func, nin, nout) specify?✗ Incorrect
The second argument
nin specifies how many input arguments the Python function takes.What type of array does a ufunc created by
np.frompyfunc() return?✗ Incorrect
Ufuncs created by
np.frompyfunc() return arrays of type object.Which of these is a benefit of using
np.frompyfunc()?✗ Incorrect
np.frompyfunc() creates ufuncs that apply Python functions element-wise on arrays.How many outputs can a function wrapped by
np.frompyfunc() return?✗ Incorrect
You can specify multiple outputs by setting
nout to more than one.Which statement is true about
np.vectorize() compared to np.frompyfunc()?✗ Incorrect
np.frompyfunc() creates ufuncs that return object arrays, while np.vectorize() returns arrays with native dtypes but is slower.Explain how
np.frompyfunc() helps apply a Python function to each element of a NumPy array.Think about how normal Python functions work on single values and how ufuncs extend that to arrays.
You got /4 concepts.
Describe the difference between
np.frompyfunc() and np.vectorize() in terms of output and performance.Consider what kind of arrays each returns and how they handle multiple outputs.
You got /4 concepts.