
Quick Contact
Python Tutorial
- What is Python?
- How to Install Python?
- Python Variables and Operators
- Python Loops
- Python Functions
- Python Files
- Python Errors and Exceptions
- Python Packages
- Python Classes and Objects
- Python Strings
- PostgreSQL Data Types
- Python Generators and Decorators
- Python Dictionary
- Python Date and Time
- Python List and Tuples
- Python Multithreading and Synchronization
- Python Modules
- What is Python bytecode?
- Python Regular Expressions
Python Panda Tutorial
- Python Pandas Tutorial
- Python Pandas Features
- Advantages and Disadvantages of Python Pandas
- Pandas Library In Python
- Pandas Series To Frame
- Python Dataframeaggregate and Assign
- Pandas Dataframe Describe
- Pandas Dataframe Mean
- Pandas Hist
- Pandas Dataframe Sum
- How to convert Pandas DataFrame to Numpy array
- Pandas Concatenation
- Pandas Shift
- Pandas Rolling
- Data Analysis With Pandas and Python
- How Python Panda Are Helpful For With Data Science
Python Selenium
- Selenium Basics
- Selenium with Python Introduction and Installation
- Navigating links using get method Selenium Python
- Locating Single Elements in Selenium Python
- Locating Multiple elements in Selenium Python
Python Flask Tutorial
Python Django
- How to Install Django and Set Up a Virtual Environment in 6 Steps
- Django MTV Architecture
- Django Models
- Django Views
- Django Templates
- Django Template Language
- Django Project Layout
- Django Admin Interface
- Django Database
- Django URLs and URLConf
- Django Redirects
- Django Cookies and Cookies Handling
- Django Caching
- Types of Caching in Django
- Django Sessions
- Django Forms Handling & Validation
- Django Exceptions & Error-handling
- Django Forms Validation
- Django Redirects
- Django Admin Interface
- Django Bootstrap
- Ajax in Django
- Django Migrations and Database Connectivity
- Django Web Hosting and IDE
- Django Admin Customization
- What is CRUD?
- Django ORM
- Django Request-Response Cycle
- Django ORM
- Making a basic_api with DRF
- Django Logging
- Django Applications
- Difference between Flask vs Django
- Difference between Django vs PHP
Numpy
- Numpy Introduction
- NumPy– Environment Setup
- NumPy - Data Types
- NumPy–Functions
- NumPy Histogram
- numPy.where
- numpy.sort
- NumPyfloor
- Matrix in NumPy
- NumPy Arrays
- NumPy Array Functions
- Matrix Multiplication in NumPy
- NumPy Matrix Transpose
- NumPy Array Append
- NumPy empty array
- NumPy Linear Algebra
- numpy.diff()
- numpy.unique()
- numpy.dot()
- numpy.mean()
- Numpy.argsort()
- numpy.pad()
- NumPyvstack
- NumPy sum
- NumPy Normal Distribution
- NumPylogspace()
- NumPy correlation
- Why we learn and use Numpy?
Tensorflow
- Introduction To Tensorflow
- INTRODUCTION TO DEEP LEARNING
- EXPLAIN NEURAL NETWORK?
- CONVOLUTIONAL AND RECURRENT NEURAL NETWORK
- INTRODUCTION TO TENSORFLOW
- INSTALLATION OF TENSORFLOW
- TENSORBOARD VISUALIZATION
- Linear regression in tensorflow
- Word Embedding
- Difference between CNN And RNN
- Explain Keras
- Program elements in tensorflow
- Recurrent Neural Network
- Tensorflow Object Detection
- EXPLAIN MULTILAYER PERCEPTRON
- GRADIENT DESCENT OPTIMIZATION
Interview Questions & Answers
NumPy–Functions
Numpy is a python package used for scientific computing. So certainly, it supports a vast variety of functions used for computation. The various functions supported by numpy are mathematical, financial, universal, windows, and logical functions. Universal functions are used for array broadcasting, typecasting, and several other standard features. While windows functions are used in signal processing. We will be learning mathematical functions in detail in this article.
Mathematical Functions in NumPy
Numpy is written purely in C language. Hence, its mathematical functions are closely associated with functions present is math.h library in C.
-
Arithmetic Functions
Function Description add(arr1, arr2,..) Add arrays element wise reciprocal(arr) Returns reciprocal of elements of the argument array negative(arr) Returns numerical negative of elements of an array multiply(arr1,arr2,…) Multiply arrays element wise divide(arr1,arr2) Divide arrays element wise power(arr1,arr2) Return the first array with its each of its elements raised to the power of elements in the second array (element wise) subtract(arr1,arr2,…) Subtract arrays element wise true_divide(arr1,arr2) Returns true_divide of an array element wise floor_divide(arr1,arr2) Returns floor after dividing an array element wise float_power(arr1,arr2) Return the first array with its each of its elements raised to the power of elements in the second array (elementwise) fmod(arr1,arr2) Returns floor of the remainder after division elementwise mod(arr1,arr2) Returns remainder after division elementwise remainder(arr1,arr2) Returns remainder after division elementwise divmod(arr1,arr2) Returns remainder and quotient after division elementwise The above-mentioned operations can be performed in the following ways :
In the given code snippet, we try to do some basic operations on the arguments, array a and array b.
Code:
import numpy as np a = np.array([10,20,30]) b= np.array([1,2,3]) print("addition of a and b :",np.add(a,b)) print("multiplication of a and b :",np.multiply(a,b)) print("subtraction of a and b :",np.subtract(a,b)) print("a raised to b is:",np.power(a,b))
Output:
In this code snippet, we try to perform division and related operations on the arguments, array a and array b. We can notice the difference between mod, remainder, divmod and simple division.
Code:
import numpy as np a = np.array([10,20,30]) b= np.array([2,3,4]) print("division of a and b :",np.divide(a,b)) print("true division of a :",np.true_divide(a,b)) print("floor_division of a and b :",np.floor_divide(a,b)) print("float_power of a raised to b :",np.float_power(a,b)) print("fmod of a and b :",np.fmod(a,b)) print("mod of a and b :",np.mod(a,b)) print("quotient and remainder of a and b :",np.divmod(a,b)) print("remainders when a/b :",np.remainder(a,b))
Output:
-
Trigonometric Functions
Function Description sin(arr) Returns trigonometric sine element wise cos(arr) Returns trigonometric cos element wise tan(arr) Returns trigonometric tan element wise arcsin(arr) Returns trigonometric inverse sine element wise arccos(arr) Returns trigonometric inverse cosine element wise arctan(arr) Returns trigonometric inverse tan element wise hypot(a,b) Returns hypotenuse of a right triangle with perpendicular and base as arguments degrees(arr) rad2deg(arr)
Covert input angles from radians to degrees radians(arr) deg2rad(arr)
Covert input angles from degrees to radians Here is an example of how to use trigonometric functions.
Code:
import numpy as np angles = np.array([0,np.pi/2, np.pi]) -----> input array angles sin_angles = np.sin(angles) cosine_angles = np.cos(angles) tan_angles = np.tan(angles) rad2degree = np.degrees(angles) print("sin of angles:",sin_angles) print("cosine of angles:",cosine_angles) print("tan of angles:",tan_angles) print("angles in radians",rad2degree)
Output:
-
Logarithmic and Exponential Functions
Function Description exp(arr) Returns exponential of an input array element wise expm1(arr) Returns exponential exp(x)-1 of an input array element wise exp2(arr) Returns exponential 2**x of all elements in an array log(arr) Returns natural log of an input array element wise log10(arr) Returns log base 10 of an input array element wise log2(arr) Returns log base 2 of an input array element wise logaddexp(arr) Returns logarithm of the sum of exponentiations of all inputs logaddexp2(arr) Returns logarithm of the sum of exponentiations of the inputs in base 2 Here is an example of using logarithmic functions:
Code:
import numpy as np a = np.array([1,2,3,4,5]) a_log = np.log(a) a_exp = np.exp(a) print("log of input array a is:",a_log) print("exponent of input array a is:",a_exp)
Output:
-
Rounding Functions
Function Description around(arr,decimal) Rounds the elements of an input array upto given decimal places round_(arr,decimal) Rounds the elements of an input array upto given decimal places rint(arr) Round the elements of an input array to the nearest integer towards zero fix(arr) Round the elements of an input array to the nearest integer towards zero floor(arr) Returns floor of input array element wise ceil(arr) Returns ceiling of input array element wise trunc(arr) Return the truncated value of an input array element wise Example of using rounding functions with numpy arrays:
Code:
importnumpy as np a = np.array([1.23,4.165,3.8245]) rounded_a = np.round_(a,2) print(rounded_a)
Output:
Code:
floor_a = np.floor(a) print(floor_a)
Output:
-
Miscellaneous Functions
Function Description sqrt(arr) Returns the square root of an input array element wise cbrt(arr) Returns cube root of an input array element wise absolute(arr) Returns absolute value each element in an input array maximum(arr1,arr2,…) Returns element wise maximum of the input arrays minimum(arr1,arr2,…) Returns element wise minimum of the input arrays interp(arr, xp, fp) Calculates one-dimensional linear interpolation convolve(arr, v) Returns linear convolution of two one-dimensional sequences clip(arr, arr_min, arr_max) Limits the values in an input array Some examples using the above functions.
Finding the Maxima:
Code:
import numpy as np a = [1,2,3] b = [3,1,2] maximum_elementwise = np.maximum(a,b) print("maxima are:",maximum_elementwise)
Output:
Clipping an array between max_limit and min_limit:
Code:
import numpy as np a = [1,2,3] b = [3,1,2] limiting_a = np.clip(a,0,2) print("limiting a between 0 and 2:",limiting_a)
Output: