Array Creation Routines: ======================== 1) zeros(): ========== ==> built-in function in NumPy. ==> use to create an array by specifying the desired shape of the array as a tuple or an integer. Syntax: numpy.zeros(shape, dtype = float, order = 'C') import numpy # creating the array with zeros a = numpy.zeros(10) print(a) ======================================== import numpy # creating the array with zeros a = numpy.zeros(10) print(a) b = numpy.zeros(6, dtype = 'i2') print(b) print(b.dtype) c = numpy.zeros([4,4],dtype = 'i1') # 4 X 4 Matrix print(c) print(c.dtype) d = numpy.zeros((7,),dtype = [('x', 'int'),('y','float')]) print(d) print(d.dtype) ========================================= ones(): ======= ==> we can able to create the array by setting the element as '1'. Syntax: numpy.ones(shape, dtype = float, order = 'C') import numpy a = numpy.ones(5) # with ones with length of 5 print(a) print(a.dtype) b = numpy.ones((4,5)) print(b) print(b.dtype) c = numpy.ones((3,4,5),dtype = 'i2') print(c) print(c.dtype) ============================================== arange(): ========= range() range(10) ==> 0, 9 range(1,20) ==> 1, 19 range(1,30,2) ==> 1,3,5,7,9,...29 ==> arange() in numpy is a built-in function which can use to create an array by generating a sequence of numbers based on specified start, stop and step values. Syntax: numpy.arange([start,] stop[,step,] dtype = None) import numpy a = numpy.arange(10) print("The Array a = ",a) print(a.dtype) b = numpy.arange(10,100,10) print("The Array b = ",b) c = numpy.arange(1,20,3,dtype = 'f2') print(c) ============================================ linspace() ========== ==> built-in function ==> used to create an array with evenly spaced values over the specified interval. ==> this can accept: start, stop and number of elements etc. Syntax: numpy.linspace(start, stop, num = x, endpoint = True, dtype = None) import numpy a = numpy.linspace(1,5,num = 8) # default endpoint = True ==> stop value can include for the creation of the array print("The Array = ",a) print(a.dtype) b = numpy.linspace(1,3,num = 5, endpoint = False) # endpoint = False ==> stop value cannot include for the array creation print(b) ===================================================== random.rand() ============= dice ==> when we can roll a dice get ==> 1/2/3/4/5/6 rand() is a built-in function of numpy random module which we can use to create an array with specifying of dimensions. Syntax: numpy.random.rand(d0, d1, d2, d3, ..... dn) import numpy a = numpy.random.rand() # can generate a value from 0 to 1 print(a) # print(a.dtype) b = numpy.random.rand(6) # can craete the array with 6 element print(b) print(b.dtype) c = numpy.random.rand(2,3) print(c) d = numpy.random.rand(2,3,4,5) print(d) ============================================== empty() ======= ==> built-in function can also use to create an array by specifying/accepting the shape of an array. Syntax: numpy.empty(shape, dtype = float, order = 'C') import numpy a = numpy.empty((2,3)) print(a) b = numpy.empty((2,3,4),dtype = 'i1') print(b)