Numpy Interview Questions

Q1. What is Numpy?

  • Numpy is a flexible, optimized, and one of the most important packages for array processing in Python. It is the fundamental package for scientific computing with Python.

Q2. Why is Numpy used in Python?

  • NumPy is a Python package for Scientific Computing. The NumPy package is used for a variety of operations. ndarray is a multidimensional array that stores values of the same datatype. These arrays are indexed similarly to Sequences, beginning with zero. NumPy is a Python package for Scientific Computing.

Q3. Where is the use of Numpy?

  • NumPy is an open-source Python numerical library. NumPy includes data structures such as multidimensional arrays and matrices. It can perform a variety of mathematical operations on arrays, including trigonometric, statistical, and algebraic routines. NumPy is a Numeric and Numarray extension.

Q4. How many dimensions can Numpy process?

  • In NumPy, an array with N dimensions is known as a ndarray.

    • ndarray is a multidimensional container that holds elements that are all the same type and size.

    • The number of dimensions in a ndarray is also referred to as its 'rank.'

    • The size of the array in each dimension is defined by a tuple of integers called shape.'

    • A 'dtype' object defines the data type of elements in ndarray.

Q5. Data Types supported by NumPy?

  • numpy.bool_ : bool
  • numpy.byte : signed char
  • numpy.ubyte : unsigned char
  • numpy.short : short
  • numpy.ushort : unsigned short
  • numpy.intc : int
  • numpy.uintc : unsigned int
  • numpy.int_ : long
  • numpy.uint : unsigned long
  • numpy.longlong :  long long

Q6. What is array slicing?

  • By mentioning the lower and upper limits, a portion of the array is selected by slicing. Slicing generates views from the original array rather than copying them.

Q7.  Given an array a = [[1,2,3],[3,4,5],[23, 45,1] find the sum of every row in array a.

  • print(a.sum(axis=0))
     # [27, 51, 9]

Q8. Features of Numpy?

  • Contains an N-dimensional array object
  •  It is interoperable; compatible with many hardware and computing platforms
  •  Works extremely well with array libraries; sparse, distributed or GPU
  •  Ability to perform complicated (broadcasting) functions
  •  Tools that enable integration with C or C++ and Fortran code 
  •  Ability to perform high-level mathematical functions like statistics, Fourier transform, sorting, searching, linear algebra, etc 

Q9. Why is the Numpy array preferred over Lists?

  • Lists in Python, while extremely efficient containers capable of a variety of functions have several limitations when compared to NumPy arrays. Vectorized operations such as element-wise addition and multiplication are not possible.

Q10. How to delete a particular column and insert a new column in the NumPy array with code?

  • Suppose we have a NumPy array:
    [[351 532 633]
    [72 12 22]
    [43 841 156]]

    new column to add:



    import NumPy as np
    input_array = np.array([[351,532,633],[72,12,22],[43,84,156]])
    new_col = np.array([[1,2,3]])
    arr = np.delete(input_array , 1, axis = 1)
    arr = np.insert(arr , 1, new_col, axis = 1)
    #prints [[351,532,633],[1,2,3],[43,84,156]}