Page 221 - Ai Book - 10
P. 221

DATA ACCESS IN PYTHON

        In the previous unit, you have learnt that Python is the most commonly used programming language in the field
        of data science. Now, you will learn how packages of Python helps us in accessing structured data within the
        Python code. The brief description of Python packages are as follows:
        NumPy

        NumPy, an  acronym of  Numerical  Python,  is  the fundamental  package for scientific
        computing with Python. The important features of NumPy are as follows:

         u   A powerful N-dimensional array object.
         u   Sophisticated (broadcasting) function
         u   Useful linear algebra, Fourier transform, and random number capabilities.
        As you know, an array is a set of multiple values of the same datatype. They can be numbers, characters, booleans,
        etc. You should always remember that only one data type can be accessed through an array. The difference
        between NumPy arrays and lists are summarised in the tabular form:

         S. No.                  NumPy Arrays                                          Lists
           1.    Arrays are created by using a specific function  Lists are created by simply enclosing a sequence of
                 from either the array  module  or NumPy  elements into square brackets.
                 Packages.

           2.    The data of arrays is homogeneous in nature.   The data of arrays is heterogeneous in nature.
           3.    Arrays are great for numerical operations.     Lists cannot directly handle numerical operations.
           4.    Arrays offer more efficient data storage.      Lists possess more memory space.
           5.    Functions  such as concatenation, appending,  Functions  such  as concatenation,  appending,
                 extending, etc are not possible within an array. extending, etc are possible within a list.
        NumPy can be imported into the Jupyter Notebook by using the given statement:

              >>>  import numpy                                #  this will import the complete numpy
                                                               #  package
              OR
              >>>  import numpy as npy                         #  this will import numpy and referred
                                                               #  as npy
              OR
              >>>  from numpy import array                     #  this will import ONLY arrays
                                                               #  from whole numy package
              OR
              >>>  from numpy import array as ary              #  this will import ONLY
                                                               #  arrays and referred as ary
        In NumPy, we can create n-dimensional arrays and are considered as an alternative to Python lists because they
        allow faster access in reading and writing items effectively and efficiently.
        So, if we compare NumPy-Arrays and Python-List then:

         u   Array is a collection of homogeneous values whereas list is a collection of heterogeneous values.
         u   In arrays data of one type does not support data of another type whereas in list it works perfectly by using
             data of one type by converting into another data type.

         u   Arrays are mainly used for mathematical operations where lists are mainly used for data management.


                                                                                                              95
                                                                                                              95
   216   217   218   219   220   221   222   223   224   225   226