0
0
NumPydata~5 mins

np.frompyfunc() for ufunc creation in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ANumber of elements in the input array
BNumber of output arguments the function returns
CData type of the output
DNumber of input arguments the function takes
What type of array does a ufunc created by np.frompyfunc() return?
AInteger array
BFloat array
CObject array
DBoolean array
Which of these is a benefit of using np.frompyfunc()?
AIt allows element-wise application of Python functions on arrays
BIt automatically compiles Python code to C
CIt converts arrays to lists
DIt only works with scalar values
How many outputs can a function wrapped by np.frompyfunc() return?
AZero outputs
BMultiple outputs
COnly one output
DOutputs must be numeric only
Which statement is true about np.vectorize() compared to np.frompyfunc()?
A<code>np.frompyfunc()</code> returns object arrays
B<code>np.frompyfunc()</code> is slower than <code>np.vectorize()</code>
C<code>np.vectorize()</code> returns arrays with native dtypes
D<code>np.vectorize()</code> creates a true ufunc
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.