Universal functions in Numpy are simple mathematical functions. It is just a term that we gave to mathematical functions in the Numpy library. Numpy provides various universal functions that cover a wide variety of operations. However, we can create our own universal function in Python. To create your own universal function in NumPy, we have to apply some steps given below:
- Define the function as usually using the def keyword.
- Add this function to numpy library using frompyfunc() method.
- Use this function using numpy.
This function allows to create an arbitrary Python function as Numpy ufunc (universal function). This method takes the following arguments :
- function – the name of the function that you create.
- inputs – the number of input arguments (arrays) that function takes.
- outputs – the number of output (arrays) that function produces.
Note: For more information, refer to numpy.frompyfunc() in Python.
- Create function with name fxn that takes one value and also return one value.
- The inputs are array elements one by one.
- The outputs are modified array elements using some logic.
arr : 1 2 3 4 5 6 7 8 9 10 mod_arr : 1 0 1 0 1 0 1 0 1 0
- Numpy ufunc | Universal functions
- Create a Numpy array filled with all ones
- Create a Numpy array with random values | Python
- Create a Numpy array filled with all zeros | Python
- Create a Pandas DataFrame from a Numpy array and specify the index column and column headers
- How to create a vector in Python using NumPy
- Create a contiguous flattened NumPy array
- Create an array which is the average of every consecutive subarray of given size using NumPy
- How to create a NumPy 1D-array with equally spaced numbers in an interval?
- Create a white image using NumPy in Python
- Python | Numpy numpy.resize()
- Python | Numpy numpy.transpose()
- Python | Numpy numpy.ndarray.__lt__()
- Python | Numpy numpy.ndarray.__gt__()
- Python | Numpy numpy.ndarray.__le__()
- Python | Numpy numpy.ndarray.__ge__()
- Python | Numpy numpy.ndarray.__eq__()
- Python | Numpy numpy.ndarray.__ne__()
- Python | Numpy numpy.ndarray.__neg__()
- Python | Numpy numpy.ndarray.__pos__()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.