ARRAY PRESENTATION - PowerPoint PPT Presentation

About This Presentation
Title:

ARRAY PRESENTATION

Description:

Learn with learnbay about array , datascience, artificial intelligence, and amchine learning. Gear start your career with learnbay. check our social media handles : – PowerPoint PPT presentation

Number of Views:26

less

Transcript and Presenter's Notes

Title: ARRAY PRESENTATION


1
BASIC OPERATIONS ON AN ARRAY
www.Learnbay.co
2
Basic Operations on an Array
  • Arithmetic operations
  • These operations are basic arithmetic
    operations like addition,subtraction,division,powe
    r etc.
  • The operation takes place element wise.
  • Eg arr1np.arange(6) O/Parray(0, 1,
    2, 3, 4, 5) print(arr13)....every no.
    is added by 3 print(arr12).... every
    no. is multiplied by 2
    print(arr1/3).... every no. is divided by 3
  • Hence element wise operations are performed
    whereas in the list it will repeat the same list
    .
  • Eg lst10,20,30 print(lst3)
  • This will repeat the list thrice.O/P
    10,20,30,10,20,30,10,20,30

3
Arithmetic operations between 2 Arrays
  • Even between two arrays the operations take place
    element wise.
  • Eg 1 arr1np.arange(6).....0,1,2,3,4,5
    arr2np.arange(6) ).....0,1,2,3,4,5
    print(arr1arr2) O/P 0 2 4 6 8 10
  • Eg 2 print(arr1gtarr2)Here element wise
    comparison takes place and returns array of
    boolean values.As the values in arr1 and arr2
    are equal it will return an array of boolean
    values.
  • O/P False False False False False False

4
NOTE
  • If number of elements in both the arrays are not
    same then it will throw an error . Hence in this
    case as the broadcasting is not possible number
    of elements in the array needs to be equal.
  • In case of scalar multiplication element wise
    multiplication takes place while in vector
    product dot product is considered . Hence number
    of rows should be equal to number of columns.
  • Eg2D array arr1np.arange(6).reshape(2,3)
  • arr2np.arange(7,13).
    reshape(2,3)
  • arr1array( 1,2,3,
    4, 5, 6)
  • arr2array( 7, 8, 9,
    10, 11, 12)
  • np.dot(arr1,arr2) OR print(arr1.dot(arr2)
  • O/P array( 31, 34, 112, 124)
  • In all these examples every time new array is
    created and the original array remains as it
    is.So the original array is not discarded.

5
2.Update/Modify the existing array
  • When an operation is performed on the array
    always new array is created and original remains
    as it is.To make changes in the orignal array we
    use the below methd.
  • arrnp.array(10,20,30)
    arr2............ arrarr2 print(arr)
  • O/P 12 22 32
  • This will make changes to the existing array.

6
3.Unary Operations
  • A single operator  or unary operation
    is one which takes and performs an operation with 
    a single operand / argument.
  • Aggregation functions such as min(),max(),etc
    also used to perform various operations on an
    array.
  • Let arr110,20,301. sum()finding sum of all
    the elements in the array.
  • arr1.sum()........O/P60
  • 2.min() finding minimum value from all
    the elements in the array
  • arr1.sum()........ O/P10
  • 3.max() finding maximum value from all
    the elements in the array
  • arr1.sum()........ O/P30

7
Finding the aggregation of elements along row or
column
  • These functions can also be used to find the
    values along the rows or columns.
  • Eg arr1np.arange(12).reshape(6,2) arr1
  • O/P array( 0, 1, 2, 3, 4, 5, 6, 7,
    8, 9, 10, 11)
  • np.sum(arr1,axis0/1)
  • np.max(arr1,axis0/1)
  • np.min(arr1,axis0/1)
  • axis0 column wise addition/min/max value
  • axis1row wise addition/min/max value

8
Universal Functions
  • MATHS FINCTIONS
  • np.add()-adds valuesnp.add(2,3)......O/P 5
  • np.multiply()-multiplication of the values
    np.multiply(2,3)......O/P 6
  • np.sqrt()-to find square root of elements in
    array
  • np.sqrt(9,16) )......O/P 3,4
  • np.log()-to find log of a value
  • np.log(1) .....O/P 0.0
  • np.square()-to find square of a value
  • np.log(5) .....O/P 25

9
Trignometric functions
  • np.sin/cos/tan(angle)-to find value of specific
    angle
  • np.sin (np.pi/2) .....O/P 1.0
  • To convert values into angles that is, to
    understand that it is value in degrees multiply
    the angle by pi/180 else it will consider them as
    usual numerical values.
  • Egnp.sin(np.array(0,30,60,90,120))(np.pi/180)
    O/P array( 0. , -0.0172444 , -0.00531995,
    0.01560319, 0.01013358)
  • To converting an array of values of angles to
    array values in radians use np.radians(angles).
  • To find inverse trignometric functions use
    arcsin(),arccos(),arctan() functions

10
Bitwise operators
  • and () (int,int) -gt int 0011 0101 returns
    the result 0001 inclusive
  • Or () (int,int) -gt int 0011 0101 returns
    the result 0111
  • not () (int) -gt int 01 returns the result 10
  • exclusive or() (int,int) -gt int 0011 0101
    returns the result 0110
  • shift left (ltlt) (int,int) -gt int 101 ltlt 2
    returns the result 10100 For shifting left, 0s
    are added on the right
  • shift right (gtgt) (int,int) -gt int 101 gtgt 2
    returns the result 1 for shifting right, bits
    are removed from the right
  • Examples print(np.bitwise_and(10,20))
    print(np.bitwise_or(10,20))
  • To get the binary representation use below
    method
  • print(np.binary_repr(30))........O/P
    11110

11
Statistical functions
  • arr_popnp.array(200,300,707,505,50,800)
  • Mean
  • finding mean of elements in the array
  • print(np.mean(arr_pop)).......O/P
    427.0
  • Median
  • finding median of elements in the array
  • print(np.median(arr_pop))
    ......O/P402.5
  • Standard deviation
  • finding standard deviation of elements in
    the array
  • print(np.std(arr_pop))
    ......O/P268.762
  • Variance
  • finding variance of elements in the array
  • print(np.var(arr_pop))
    ......O/P72233.333
Write a Comment
User Comments (0)
About PowerShow.com