Programming and Problem Solving Through Python Language Theory Question

NumPy Basic - Set 2

  1. What is the purpose of zeros() function used in Numpy array ?
    1. To make a Matrix with all diagonal element 0
    2. To make a Matrix with first row 0
    3. To make a Matrix with all element 0
    4. None of the above
    Answer : C
    Explain : Python numpy. zeros() function returns a new array of given shape and type, where the element's value as 0
  2. NumPY stands for?
    1. Numbering Python
    2. Number in Python
    3. Numerical Python
    4. Number for Python
    Answer : C
    Explain : NumPy, which stands for Numerical Python, is a library consisting of multidimensional array objects.
  3. What will be the output of the following ?
    import numpy as np
    a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
    print(a[2,2])
    1. 7
    2. 10
    3. 11
    4. 8
    Answer : C
    Explain : a[2,2] means 2 index value container and 2 index value no. of that container.
  4. What is the output of the following code?
    import numpy as np
    a = np.array([1,2,3,5,8])
    b = np.array([0,1,5,4,2])
    c = a + b
    c = c*a
    print (c[2])
    1. 6
    2. 24
    3. 0
    4. None of these
    Answer : B
    Explain : Here c=a+b = [ 1 3 8 9 10], then c=c*a = [ 1 6 24 45 80]. Now Value c[2] is 24.
  5. What is the output of the following code ?
    import numpy as np
    a = np.array([[1,2,3]])
    print(a.shape)
    1. (2, 3)
    2. (1, 3)
    3. (3, 3)
    4. None of these
    Answer : A
    Explain : shape gives the shape of array (row,columns)
  6. What will be the output of the following ?
    import numpy as np
    print(np.maximum([2, 3, 4], [1, 5, 2]))
    1. [1 5 2]
    2. [1 5 4]
    3. [2 3 4]
    4. [2 5 4]
    Answer : D
    Explain : maximum function compare the maximum value between elements. In array, 1st column compare value to 1st column of other array. Like 2 or 1 maximum value is 2, 3 or 5 maxi. value is 5 and 4 or 2 maximum value is 4. Now it gives [2,5,4].
  7. What will be the output of the following ?
    import numpy as np
    a = np.array( [2, 3, 4, 5] )
    b = np.arange(4)
    print(a+b)
    1. [2 3 4 5]
    2. [3 4 5 6]
    3. [1 2 3 4]
    4. [2 4 6 8]
    Answer : D
    Explain : arange () is used to arange an array. Here value of b =np.arange(4) = [0 1 2 3] (4 is stop value).Now a+b=[2,3,4,5]+[0,1,2,3]=[2 4 6 8].
  8. What is the output of the following code ?
    import numpy as np
    y = np.array([[11, 12, 13, 14], [32, 33, 34, 35]])
    print(y.ndim)
    1. 1
    2. 2
    3. 3
    4. 0
    Answer :B
    Explain : ndim () is used to find the dimension of array.
  9. What will be the output of the following ?
    import numpy as np
    print(np.minimum([2, 3, 4], [1, 5, 2]))
    1. [1 5 2]
    2. [1 2 5]
    3. [2 3 4]
    4. [1 3 2]
    Answer : D
    Explain : minimum check the minimum value column wise.
  10. Which attribute is used to find the data type of numpy array ?
    1. type(array)
    2. dtype
    3. objects.type(array)
    4. numpy(type)
    Answer : B
    Explain : dtype is used to find out the data type of element in numpy array.
  11. What will be output for the following code ?
    import numpy as np
    a = np.array([1,2,1,5,8])
    b = np.array([0,1,5,4,2])
    c = a + b
    c = c*a
    print (c[2])
    1. 6
    2. 10
    3. 0
    4. None of these
    Answer : A
    Explain : Here, c=a+b=[1,3,6,9,10] and c=c*a =[1,6,6,45,80]. print(c[2]) is 6.
  12. What is the output of the following code ?
    import numpy as np
    a = np.array([1.1,2,3])
    print(a.dtype)
    1. int32
    2. float64
    3. float
    4. None of above
    Answer : B
    Explain : float64 is for float value and int32 is for integer value only.
  13. What will be output for the following code ?
    import numpy as np
    a = np.array([11,2,3])
    print(a.min())
    1. 2
    2. 1
    3. 11
    4. 3
    Answer : A
    Explain : min gives the minimum value from the array.
  14. What will be output for the following code ?
    import numpy as np
    a = np.array([11,2,3])
    print(a.max())
    1. 2
    2. 1
    3. 11
    4. 3
    Answer : C
    Explain : max() gives the maximum value from the array.
  15. What are the attributes of numpy array ?
    1. shape, dtype, ndim
    2. objects, type, list
    3. objects, non vectorization
    4. Unicode and shape
    Answer : A
    Explain : Numpy attributes are : ndim, shape, size, dtype, itemsize, and reshape.

Next Set

1