Page 290 - Ai_C10_Flipbook
P. 290

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

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

                        [[1. 1. 1. 1.]
                         [1. 1. 1. 1.]
                         [1. 1. 1. 1.]]

                 • 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]







                    288     Artificial Intelligence Play (Ver 1.0)-X
   285   286   287   288   289   290   291   292   293   294   295