Programming and Problem Solving Through Python Language Theory Question

NumPy Basic

  1. What is NumPy in Python primarily used for ?
    1. Web development
    2. Data visualization
    3. Scientific computing and data analysis
    4. Machine learning algorithms
    Answer : C
    Explain : NumPy is stands for Numerical Pyhton. It is used for working with arrays.
  2. Which of the following data structure is a core component of NumPy ?
    1. List
    2. Dictionary
    3. Tuple
    4. ndarray (N-dimensional array)
    Answer : D
    Explain : ndim is used to display the dimension of array.
  3. How can you create a 1D array in NumPy ?
    1. numpy.array([1, 2, 3])
    2. numpy.ndarray(1, 2, 3)
    3. numpy.list([1, 2, 3])
    4. numpy.array(1, 2, 3)
    Answer : A
    Explain : One dimensional array contains elements only in one dimension.
  4. Solve the given code ?
    import numpy as n
    a= n.array([1,2,3])
    b= n.array([1,2,3])
    c=a+b
    print(c)
    
    1. [2,4,6]
    2. [1,2,3]
    3. [1,2,3]
    4. [2 4 6]
    Answer : D
    Explain : print(c) means we want to print the array so array come in [] without comma.
  5. What will be output of following code ?
    import numpy as n
    nb=n.arange(4)
    print(nb)
    
    1. [0 1 2 3]
    2. [0 1 2 3 4]
    3. [0, 1, 2, 3]
    4. None of the above
    Answer : A
    Explain : It gives value in array.
  6. What will be the output of following code ?
    import numpy as n
    print(n.minimum([2,3,4],[1,5,2]))
    
    1. [1 2 5]
    2. [1 5 2]
    3. [2 3 4]
    4. [1 3 2]
    Answer : D
    Explain :It check the value minimum. Like 2 or 1 min. is 1, 3 or 5 min. is 3 , 4 or 2 min. is 2.
  7. Solve the given 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 above
    Answer : A
    Explain : First it sum c =a+b=[ 1 3 6 9 10] Then c*a=[ 1 6 6 45 80]. At, last print(c[2]) index value c[2] is 6
  8. What are the attributes of numpy array ?
    1. shape, dtype, ndim
    2. object, type, list
    3. objects, non, vectorization
    4. Unicode and shape
    Answer : A
    Explain : ndim, shape, size, dtype, reshape are the attributes os numpy.
  9. how can we check all fucntion in numpy ?
    1. import numpy
      print(dir(numpy))
    2. import numpy
      print(info(numpy))
    3. import numpy
      print((numpy.list))
    4. None of the above
    Answer :A
    Explain :The dir() function returns all properties and methods of the specified object, without the values.
  10. Which NumPy function is used to create an array filled with zeros ?
    1. empty()
    2. zeros()
    3. ones()
    4. copy()
    Answer : B
    Explain : zeros() creates an array filled with zero.
  11. The primary purpose of the copy() function in NumPy is to :
    1. Create an empty array
    2. Create an array with ones
    3. Duplicate an existing array with its data
    4. Create an array with zeros
    Answer : C
    Explain : copy() used to copy array.
  12. What is the output of following code ?
    import numpy as np 
    a=np.array([12,22,33,44])
    print(a.dtype)
    
    1. int
    2. integer
    3. int32
    4. None of above
    Answer : C
    Explain : int32 means that it contain integer value.Int32 is an immutable value type that represents signed integers with values
  13. Can we convert tuple in array ?
    1. Yes
    2. No
    3. Can't say
    4. May be
    Answer : A
    Explain : Yes, we can convert tuple in array.
  14. What will be the output of following code ?
    import numpy as np 
    arr = np.array([[1, 2, 3, 4],[45, 64, 47, 48]])
    print(arr.shape)
    	
    
    1. (3, 4)
    2. (4, 4)
    3. (2, 4)
    4. (4, 2)
    Answer : C
    Explain : Here is 2 row and 4 element in it. It is 2-D (2 dimensional).
  15. What will be output for the following code ?
    import numpy as np
    a = np.array([[1,2,3],[0,1,4],[11,22,33]])
    print (a.size)
    1. 1
    2. 3
    3. 4
    4. 9
    Answer : D
    Explain : size method returns the total number of elements of in an array.

Next Set

2