Loading, please wait...

A to Z Full Forms and Acronyms

NumPy Universal functions(part- 1) |Python tutorial

This article is an introduction of NumPy ufuncs , Arguments it takes , its Attributes and methods .

NumPy Universal functions(part- 1) |Python tutorial

Introduction:

ufuncs stands for ‘universal Functions’ and these are the Numpy functions that work on the ndarray object.

ufuncs are used to implement vectorization( i.e converting iterative statements into a vector-based on operation) in NumPy. Vectorization over iterative statements is faster as modern CPUs are optimized for such operations. There are more than 60 ufuncs defined in numpy on one or more types, covering a wide variety of operations.

Arguments:

where: Boolean array or condition defining where the operations should take place.

dtype: it defines the return type of elements.

out: it defines the output array to store the returned value.

Attributes of Universal function:

_doc_: it’s a docstring for each ufuncs.

_name_: The name of ufuncs 

ufunc.nin: The number of inputs.

ufunc.nout: The number of outputs.

ufunc.nargs: The number of arguments.

ufunc.types: It returns a list with types grouped input -> output

ufunc.identity: the identity value.

ufunc.signature: Definition of core elements a generalized universal function operates on. 

Methods of Universal function:

There are five methods of ufuncs & these methods make sense on scalar ufuncs that takes only two arguments as input and returns one output argument. If you try to call these methods on other ufuncs ValueError will be raised. ufuncs methods are listed below.

1. ufunc.reduce():

This method reduces a’s dimension by one, by applying ufunc along one axis.

Syntax:

ufunc.reduce(a, axis=0, dtype=None, keepdims=False, out=None)

2. ufunc.accumulate():

This method accumulates the result of applying the operator to all elements.

Syntax:

ufunc.accumulate(a, axis=0, dtype=None, out=None)

3. ufunc.reduceat():

This method performs reduce at specified slices over a single axis.

Syntax: 

 ufunc.reduceate(a, indices, axis=0,dtype=None,out=None)

4.ufunc.outer(): 

This method applies the ufunc operator to all pairs (a,b) with 'a' in Array1 and 'b' in Array2.

Syntax:

ufunc.outer(a , b ,**kwargs)

5. ufunc.at():

This method performs unbuffered in place operation on operand ‘a’ for elements specified by indices.

Syntax: 

ufunc.at(a, indices, b=None)

In the upcoming article, you will learn methods of ufuncs in brief… 

I just hope you like the content, please don’t forget to comment and share the content with your friends. Stay tuned with us for more articles like this.

Thanks for reading this article.

With regards,

Keep learning

A to Z Full Forms and Acronyms

Related Article