Double Revolving field theory-how the rotor develops torque
Numpy_defintion_description_usage_examples.pptx
1. Outline
❑ Jupyter Notebook
❑ Numpy
❑ Importing Package
❑ Creating an Array
❑ Generating arrays using built-in functions
❑ Shape and Reshape an Array
❑ Numpy Operations
❑ Access Elements from an Array
❑ Advantages of Numpy
❑ Matrix operations
2. Jupyter Notebook
❑ Jupyter Notebook is a web-based interactive IDE for
Executing the Python.
❑ Install the Anaconda Navigator to your Machine and
open the Navigator.
3. Jupyter Notebook
❑ Launch the Jupyter Notebook; once Launch means (it
will take some time).
❑ Open the Jupyter Notebook (Type Jupyter Notebook in
Start Menu Search)
4. Importing Package
❑Numpy standards for Numerical Python
❑It is mainly used for handling the mathematical
operations.
❑Import the Numpy packages using import command
Package Name Alias Name of Numpy
5. Create an Array
❑Collection of ordered data elements of basic data types
❑Syntax: np.array(object)
Array List
7. Run Time Inputs
number_list = [] n = int(input("Enter the list size "))
print("n")
for i in range(0, n):
print("Enter number at index", i, )
item = int(input())
number_list.append(item)
print("User list is ", number_list)
8. Generate arrays using linspace
❑np.linspace()-returns equally spaced numbers within the
given range based on the sample number
❑Syntax:
np.linspace(start,stop,num)
❑start -start of interval range
❑stop -end of interval range
❑num-number of samples to be generated
9. Generate arrays using arange()
❑np.arange()-returns equally spaced numbers with in the
given range based on step size
❑Syntax:
np.arange(start,stop,step)
❑start -start of interval range
❑stop -end of interval range
❑step -step size of interval
❑Generate an array with start=1and stop=100 by specifying
step=2
10. Generate arrays using zeros()
❑np.zeros()-returns an array of given shape and type
filled with zeros
❑Syntax:
np.zeros(shape,dtype)
❑shape -integer or sequence of integers
❑dtype-data type (default: float)
1-D
2-D
11. Generate arrays using ones()
❑np.ones()-returns an array of given shape and type
filled with ones
❑Syntax:
np.ones(shape,dtype)
❑shape -integer or sequence of integers
❑dtype-data type (default: float)
1-D 2-D
12. Generate arrays using eye()
❑np.eye()-returns an array of given shape and diagonals
are filled with ones and rest of the diagonals are filled with
zeros.
❑Syntax:
np.eye(shape)
13. Generate arrays using random.rand()
❑np.random.rand()-returns an array of given shape filled
with random values
❑Syntax: numpy.random.rand(shape)
❑shape -integer or sequence of integers
❑The range of random number should be between 0-1
1-D
2-D
14. Shape an array
❑np.shape()-returns dimension of an array
❑Syntax: np.shape(var)
1-D 2-D
❑In 1-D, return shape as 5
❑In 2-D, will return 2rows and 3 columns.
16. Numpy addition
❑np.sum()-returns sum of all array elements
❑Syntax: np.sum(array,axis)
❑array() –input array
❑axis() –axis along which sum should be calculated
❑If axis= None ; calculate overall sum
17. Numpy addition
❑if axis=0; calculate sum along with column wise
❑If axis=1; calculate sum along with row wise
Column wise sum Row wise sum
24. Subset of arrays
❖Subset a 2x2 array from the original
array m
❖Consider the first two rows and
columns from m
❖Print subset array sub
25. Subset of arrays
❖Here the value 1should be updated to 12
❖Print the updated array
❖Modifying the subset will automatically update the
original array also
26. Transpose of an array
np.transpose()- permute the dimensions of array
❑Syntax: np.transpose(array)
Output
27. Advantages of Numpy
❑timeit module can be used to measure the execution time
for snippets of code
❑Comparing the processing speed of a list and an array
using an addition operation
List Array
❑Creating a list ❑Creating a array
28. Create a Matrix
❑matrix()- returns a matrix from an array type object or
string of data
❑Syntax: np.matrix(data)
❑shape- returns number of rows and columns from a
matrix
❑shape[0]- returns the no. of row
❑shape[1]-returns the no. of columns.
❑size()- returns total no of elements.
29. Modifying matrix using insert()
❑insert()- adds values at a given position and axis in a
matrix
❑Syntax: np.insert(matrix, obj, values, axis)
❑marix- input matrix
❑obj- index position
❑values-matrix of values to be inserted
❑axis- axis=0- row insert otherwise- column wise insertion
30. Matrix Operations
Row Insertion Column Insertion
S.
No.
Function Description
1. np.add(M1,M2) Performs element wise addition between
two matrix
2. np.subtract(M1,M
2)
Performs element wise subtraction between
two matrix
3. np.dot(M1,M2) Performs element wise multiplication
between two matrix
4. np.divide(M1,M2) Performs element wise division between
two matrix