Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 152 - 2615_KEC
P. 152

    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 NumPy package
                      OR

                      from numpy import array as ary  #this will import ONLY arrays and referred as ary

                      ARRAYS
                      Arrays are an ordered collection of values of the same data type that can be arranged in one

                      or more dimensions. They can store numbers, characters, Boolean values, etc. The elements are
                      referred to using index numbers (positions) that start from 0. Almost all programming languages
                      support arrays in one form or another.

                          A one-dimensional array is called a Vector.
                          A two-dimensional array is called a Matrix.

                          An array with multiple dimensions is called an n-dimensional array.
                      In NumPy, we can create n-dimensional arrays, which are considered an alternative to Python
                      lists because they allow faster access to reading and writing elements efficiently. The NumPy
                      library provides a large set of built-in functions in the form of modules and packages for creating,
                      manipulating and transforming NumPy arrays.

                      NUMPY ARRAYS VS PYTHON LISTS
                      The difference between NumPy Arrays vs Python Lists is shown in the below table:

                           Feature                     NumPy Array                                Python List

                       Data Type         Homogeneous  (stores  elements  of the  Limited to a small area
                                         same type)
                       Data Type         Does not support mixed types within the  Risk of unauthorised access if not

                       Conversion        same array.                                   properly secured
                       Memory            More memory-efficient.                        Network problems may affect all
                       Efficiency                                                      connected devices

                       Accessibility     Requires importing NumPy.                     Limited to a small area
                       Mathematical  Supports direct mathematical operations  Limited to a small area
                       Operations        on all elements.

                       Usage             Mostly  used  for scientific  computing,  Limited to a small area
                                         numerical operations and data analysis.

                      150   Premium Edition-VIII

| 147 148 149 150 151 152 153 154 155 156 157 |