Posts

Showing posts from September, 2019

Python - Numpy - ndarray - How to create random array of integer - multidimension

Random import numpy as np randarr= np.random.randint( 0,100, size = (2,4)) randarr= np.random.randint( randomNoStartingFromInclusive, randomNoEndingExclusive, size = (NoOfRows, NoOfColumns) )

Python - numpy - ndarray

Multiple ways to create ndarrays   - matrices import numpy as np create1 = np.array([1,2,3,4])    ## creates a 1 dimensional array with 4 elements - takes input as 1 list create1 = np.array( [ [1,2,3,4],[5,6,7,8] ] )  ## creates 2 dimensinal array -- takes input as 2 lists. notice the big square bracktes outside create1 = np.array( [ [1,2,3,4],[5,6,7,8]..... [n1,n2,n3,n4] ] )  ## creates n dimensinal array -- takes input as 2 lists. create1 = np.arrange # create a copy of ndarray copy1 = np.array(create1) # this will create a new copy of array instead of assigning refrence to it

Python - How to Create Copy of a List

x = [1,2,3] y = x  --- y will reference the same list in memory as x but if we want to make a new copy of list x and assign the reference to y use below y = list(x)    --- this will make a copy of list x in memory and assign the reference to y

Python - String concatenation

String concatenation is done by using + operator '1' + '2' '12'