view(): ======= ==> built-in function can use to create an array from another array the array object in view is same as original array but possible to change its type. a = [1,3,5,7,9] a_copy = [1,3,5,7,9] a_view = [1.0,3.0,5.0,7.0,9.0] Syntax: source-array.view(dtype) import numpy a = numpy.array([1.2,2.1,1.3,3.1,1.4,4.1]) print("The Original Array = ",a) print("Type = ",a.dtype) # b = a.copy(dtype = 'i2') b = a.copy() print("b = ",b) print("type = ",b.dtype) c = a.view(dtype = 'i1') print("c = ",c) print("Type = ",c.dtype) ========================================== reshape(): ========== array ==> 3 X 4 ==> 12 reshape to ==> 4 X 3 ==> 12 reshape ==> 6 X 2 ==> 12 Note: ==== the reshape parameters product must be equal to total number of elements in the original array, then only the reshape is possible. ==> reshape() built-in function can be use to reshape the original array and create the new array. Syntax: original_array.reshape((parameters)) for 2d-array: x, y for 3d-array: x, y, z import numpy a = numpy.array([1,2,3,4,5,6]) # 1d-array b = numpy.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]]) # 2d-array print("a = ",a) print("b = ",b) r1 = a.reshape((3,2)) r2 = a.reshape((2,3)) # r3 = a.reshape((3,3)) r3 = b.reshape((12,)) r4 = b.reshape((1,3,4)) print("r1 = ",r1) print("r2 = ",r2) print("r3 = ",r3) print("r4 = ",r4) ================================================ Array Indexing: =============== import numpy a = numpy.array([1,2,3,4,5]) b = numpy.array([[1,2,3],[4,5,6],[7,8,9]]) # 2d-array # Positive Indexing values print(a[0],a[1],a[2],a[3],a[4]) print(b[0],b[1],b[2]) print(b[0][0],b[0][1],b[0][2]) print(b[1][0],b[1][1],b[1][2]) print(b[2][0],b[2][1],b[2][2]) # Negative Indexing Values print(a[-1],a[-2],a[-3],a[-4],a[-5]) print(b[-1],b[-2],b[-3]) print(b[-1][0],b[-1][1],b[-1][2]) ============================================= Array Slicing: ============== import numpy a = numpy.array([1,2,3,4,5,6,7,8,9,10]) print(a[::1]) print(a[::-1]) print(a[2:6]) print(a[-10:-4]) ================================================= # WAP TO CREATE THE ARRAY WITH RANGE OF OBJECTS. import numpy objects = range(1,11) a = numpy.array(objects) b = numpy.array(range(10,101,10)) print("Array with range of objects = ",a) print("Array with range of objects = ",b) ==================================================== logspace(): =========== log10 log2 ==> built-in function can use to generate an array with log values these objects can be evenly spaced. Syntax: numpy.logspace(start, stop, num, endpoint = True, base = 10/2, dtype) import numpy a = numpy.logspace(1,11,6,base = 2) print("a = ",a) =================================================== Array-Iteration: ================ 1) Using for loop: ================== import numpy a = numpy.array([1,3,5,7,9]) # 1d-array b = numpy.array([[1,2,3],[4,5,6],[7,8,9]]) c = numpy.array([[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]]]) for i in a: print(i) for i in a[::-1]: print(i) for i in b: print(i) for i in b: for j in i: print(j,end = "\t") print() print("Printing 2d-arrays:") for i in c: print(i) print("Printing 1D-array:") for i in c: for j in i: print(j) print("3d-Array ELements = ") for i in c: for j in i: for k in j: print(k,end = "\t") print()