Skip to main content

Posts

Showing posts from April, 2019

some Python (Numpy Pandas)

############ numpy ############################# #importing numpy import numpy as np #numpy matrices are strictly 2d and numpy arrays can be multidimensional, #numpy matrices are subclass of numpy nd array #creating numpy array from list mylist = [ 1 , 3 , 6 , 2 , 7 , 4 , 8 ] x = np . array ( mylist ) print ( x ) x = np . array ([ 1 , 3 , 6 , 2 , 7 , 4 , 8 ]) print ( x ) #creating 2d array x = np . array ([[ 1 , 2 , 3 ],[ 2 , 3 , 4 ]]) print ( x ) ## if you do something like below x = np . array ([[ 1 , 2 , 3 ],[ 2 , 3 ]]) #lenth of two lists dont match print ( x ) #you will get the output as [list([1, 2, 3]) list([2, 3])] #shape of the array x . shape #outputs a tuple (row, column) #like range n = np . arange ( 0 , 11 , 2 ) #np.arange(start, end, gap) print ( n ) #[0,2,4,6,8,10]#always excludes the last value #reshaping arrays m = n . reshape ( 2 , 3 ) #here we are reshaping it in 2 by 2d array print ( m ) #also you can give only th...