Array Creation: =============== array(): ======= Syntax: numpy.array(object, dtype = None, copy = True, order = None, subok = True/False, ndmin = 0) order = A (both row and column) C (in row) F (in Column) 1d array: [1,2,3] 2d-array: collection of 1-d arrays [[1,2,3],[3,4,5],[5,6,7]] 3d-array: collection of 2-d arrays [[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]] Creation of an array by specifying the Dimension value: ======================================================= Syntax: numpy.array(object, ndmin = value) import numpy as rk # create an array with ndmin value a = rk.array([1,2,3,4],ndmin = 3) b = rk.array([[1,2,3,4,5],[5,4,3,2,1]],ndmin = 4) print(a) print(b) =========================================================== shape ===== ==> a built-in parameter in NumPy which we can use to get the shape of the array ==> shape of array ==> row and column Syntax: array-name.shape Ex: a = [[1,2,3], [4,5,6], [7,8,9]] ==> 2-d array ==> consisting of three 1d-arrays. Each 1d-array ==> row the total rows ==> 3 In this row: three elements element ==> value at column total columns => 3 Shape ==> 3 X 3 Ex: [[[1,2,3],[4,5,6]], [[3,2,1],[6,5,4]], [[7,8,9],[10,11,12]]' ==> 3d-array In this definition: total 2d-arrays ==> 3 (length of 3d-array) each 2d-array ==> 2-1darrays (length of 2d-array) each 1d-array ==> 3-elements (length of 1d-array) 3 X 2 X 3 Ex: [[[[1,2],[3,4]],[[5,6],[7,8]]] [[[8,7],[6,5]],[[4,3],[2,1]]] [[[1,3],[5,7]],[[2,4],[6,8]]]] ==> 4d-array In this definition: total number of 3d-arrays ==> 3 (length of 4d-array = 3) each 3d-array ==> 2 2d-arrays ==> length of 3d-array = 2 each 2d-array ==> 2 1d-arrays ==> length of 2d-array = 2 each 1d-array ==> 2 elements ==> length of 1d-array = 2 Shape ==> 3 X 2 X 2 X 2 import numpy a = numpy.array([1,2,3,4]) # 1-d array b = numpy.array([[1,2,3],[4,5,6]]) # 2d-array c = numpy.array([[[1,2,3,4],[5,6,7,8]],[[4,3,2,1],[8,7,6,5]]]) # 3d-array d = numpy.array([[[[1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16]]]]) # 4d-array print("The Shape of array a = ",a.shape) print("The Shape of array b = ",b.shape) print("The Shape of array c = ",c.shape) print("The Shape of array d = ",d.shape) ============================================================ strides: ======== Syntax: array-name.strides Ex: a = [[1,2,3], [4,5,6], [7,8,9]] ==> 2-d array ==> consisting of three 1d-arrays. 3 X 3 3-rows and 3-columns strides ==> 12-bytes, 4-bytes Ex: [[[1,2,3],[4,5,6]], [[3,2,1],[6,5,4]], [[7,8,9],[10,11,12]]' ==> 3d-array strides: 24-bytes, 12-bytes, 4-bytes Ex: [[[[1,2],[3,4]],[[5,6],[7,8]]] [[[8,7],[6,5]],[[4,3],[2,1]]] [[[1,3],[5,7]],[[2,4],[6,8]]]] ==> 4d-array strides: 32-bytes, 16-bytes, 8-bytes, 4-bytes import numpy a = numpy.array([1,2,3,4]) # 1-d array b = numpy.array([[1,2,3],[4,5,6]]) # 2d-array c = numpy.array([[[1,2,3,4],[5,6,7,8]],[[4,3,2,1],[8,7,6,5]]]) # 3d-array d = numpy.array([[[[1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16]]]]) # 4d-array print("The Strides of array a = ",a.strides) print("The Strides of array b = ",b.strides) print("The Strides of array c = ",c.strides) print("The Strides of array d = ",d.strides)