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

Some Important Functions


                      Type           Function                                   Example

               Type of an object   type(ARR)
                                                   [1]:   import numpy as np
               i.e. array
                                                          ARR = np.array([1,2,3,4])
                                                          print(type(ARR))

                                                          <class 'numpy.ndarray'>

               Check the           ARR.ndim
                                                   [1]:   import numpy as np
               dimensions of
                                                          ARR = np.array([[1,2,3,4],[3,4,5,6]])
               an array
                                                          print(ARR.ndim)
                                                          2


               Shape of an array  ARR.shape
                                                   [1]:   import numpy as np
               i.e. length of the
                                                          ARR = np.array([[1,2,3,4],[3,4,5,6]])
               array dimensions
                                                          print(ARR.shape)
                                                          (2, 4)


               Size of an array    ARR.size
                                                   [1]:   import numpy as np
               i.e. counts the
                                                          ARR = np.array([[1,2,3,4],[3,4,5,6]])
               number of                                  print(ARR.size)
               elements
                                                          8

               Datatype of         ARR.dtype
                                                   [1]:   import numpy as np
               elements stored
                                                          ARR = np.array([[1,2,3,4],[3,4,5,6]])
               in the array
                                                          print(ARR.dtype)
                                                          int32


               Maximum value       ARR.max()
                                                   [1]:   import numpy as np
               in the  element
                                                          ARR = np.array([[10,34,45,23,12]])
               of the array
                                                          print(ARR.max())
                                                          45

               Row wise &          ARR.
               column wise         max(axis=1)     [1]:   import numpy as np
               maximum value       for row                ARR = np.array([[11,2,13,4],[3,4,5,6]])
                                                          print("Rowwise max :",ARR.max(axis=1))
                                                          print("Column wise max :",ARR.max(axis=0))
                                   ARR.                   Rowwise max : [13  6]
                                   max(axis=0)            Column wise max : [11  4 13  6]
                                   for column




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