Page 448 - AI Ver 3.0 class 10_Flipbook
P. 448

• Creating two-dimensional array of 3 rows and 3 columns with all zeroes as value:


                 [1]:   import numpy as np
                        a = np.zeros((3,3))
                        print(a)

                        [[0. 0. 0.]
                         [0. 0. 0.]
                         [0. 0. 0.]]

                 • Creating two-dimensional array of 3 rows and 4 columns with all six as value:

                 [1]:   import numpy as np
                        a = np.full((3,4),6)
                        print(a)
                        [[6 6 6 6]
                         [6 6 6 6]
                         [6 6 6 6]]

                 • We can create two-dimensional (2-D) arrays by passing nested lists to the array() function.


                 [1]:   import numpy as np
                        a = np.array([[15,'Pranay',96],[16,'Pranya',92]])
                        print(a)
                        [['15' 'Pranay' '96']
                         ['16' 'Pranya' '92']]

              Using Mathematical Operators on Integer Array

              Following table shows the use of mathematical operators on integer array:

                   Operator                                            Example

                       **
                                   [1]:  import numpy as np
                 (Exponential)           marks1 = np.array([1,2,3,4])

                                         marks2=np.array([2,1,2,1])
                                         print(marks1**marks2)
                                         print("marks1 to the power of 3 is:",marks1**3)

                                         [1  2  9  4]
                                         2 marks extra : [ 1 8 27 64]


                       +
                                   [1]:  import numpy as np
                   (Addition)            marks1 = np.array([7,8,5,4])
                                         marks2=np.array([5,6,4,7])
                                         print(marks1+marks2)
                                         print("2 marks extra:",marks1+2)

                                         [12 14 9 11]
                                         2 marks extra : [ 9 10 7 6]






                    446     Touchpad Artificial Intelligence (Ver. 3.0)-X
   443   444   445   446   447   448   449   450   451   452   453