Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 4 MCQs Array Operations using NumPy

ECE181 — Introduction To Python 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 arrays vs lists Easy

    Which Python library provides the ndarray object used for numerical arrays?

  2. Question 2 of 60 arrays vs lists Easy

    What is a key difference between a NumPy array and a Python list?

  3. Question 3 of 60 arrays vs lists Easy

    Which function is used to create a NumPy array from a Python list?

  4. Question 4 of 60 arrays vs lists Easy

    Compared to Python lists, NumPy arrays are generally preferred for numerical computation because they are:

  5. Question 5 of 60 data types Easy

    Which attribute is used to check the data type of elements in a NumPy array?

  6. Question 6 of 60 data types Easy

    What does the NumPy data type int64 represent?

  7. Question 7 of 60 data types Easy

    Which method changes the data type of an existing NumPy array?

  8. Question 8 of 60 data types Easy

    If an array is created as np.array([1.0, 2.0, 3.0]), its default data type will be:

  9. Question 9 of 60 array operations Easy

    Given a = np.array([1, 2, 3]), what is the result of a + 2?

  10. Question 10 of 60 array operations Easy

    Which attribute returns the shape (dimensions) of a NumPy array?

  11. Question 11 of 60 array operations Easy

    Given a = np.array([1, 2, 3]) and b = np.array([4, 5, 6]), what is a * b?

  12. Question 12 of 60 array operations Easy

    Which function reshapes an array without changing its data?

  13. Question 13 of 60 array operations Easy

    What does np.arange(0, 5) produce?

  14. Question 14 of 60 statistical functions Easy

    Which NumPy function computes the average of array elements?

  15. Question 15 of 60 statistical functions Easy

    What does np.max() return for a NumPy array?

  16. Question 16 of 60 statistical functions Easy

    Which function computes the standard deviation of a NumPy array?

  17. Question 17 of 60 statistical functions Easy

    Given a = np.array([2, 4, 6]), what does np.sum(a) return?

  18. Question 18 of 60 broadcasting Easy

    What does broadcasting in NumPy allow you to do?

  19. Question 19 of 60 broadcasting Easy

    When you add a scalar to a NumPy array, broadcasting causes the scalar to be:

  20. Question 20 of 60 broadcasting Easy

    For broadcasting to work between two arrays, their dimensions must be:

  21. Question 21 of 60 arrays vs lists Medium

    Given import numpy as np, what is the output of the following code?
    python
    lst = [1, 2, 3]
    arr = np.array([1, 2, 3])
    print(lst 2, arr 2)

  22. Question 22 of 60 arrays vs lists Medium

    Which statement best explains why NumPy arrays are generally faster than Python lists for numerical computation?

  23. Question 23 of 60 data types Medium

    What will be the dtype of the array created below?
    python
    arr = np.array([1, 2, 3.0, 4])

  24. Question 24 of 60 data types Medium

    What is the output of the following code?
    python
    arr = np.array([1, 2, 3], dtype=np.int8)
    arr[0] = 300
    print(arr[0])

  25. Question 25 of 60 data types Medium

    Which code correctly converts a float array a into an integer array without changing the original?

  26. Question 26 of 60 array operations Medium

    Given arr = np.arange(12).reshape(3, 4), what does arr[:, 1] return?

  27. Question 27 of 60 array operations Medium

    What is the result of the following code?
    python
    a = np.array([[1, 2], [3, 4]])
    print(a.sum(axis=0))

  28. Question 28 of 60 array operations Medium

    Given arr = np.array([10, 20, 30, 40, 50]), what does arr[::-2] return?

  29. Question 29 of 60 array operations Medium

    What is the difference between np.dot(a, b) and a * b for two 2D arrays of the same shape?

  30. Question 30 of 60 array operations Medium

    What is the output of the following code?
    python
    arr = np.array([1, 2, 3, 4, 5])
    print(arr[arr % 2 == 0])

  31. Question 31 of 60 statistical functions Medium

    Given arr = np.array([2, 4, 6, 8]), what does np.std(arr) compute and its approximate value?

  32. Question 32 of 60 statistical functions Medium

    For a = np.array([[1, 2], [3, 4]]), what does np.mean(a, axis=1) return?

  33. Question 33 of 60 statistical functions Medium

    Which function returns the index of the maximum value in an array rather than the value itself?

  34. Question 34 of 60 statistical functions Medium

    What is the output of the following code?
    python
    arr = np.array([3, 1, 4, 1, 5, 9, 2])
    print(np.median(arr))

  35. Question 35 of 60 statistical functions Medium

    Given arr = np.array([10, 20, 30, 40]), what does np.cumsum(arr) return?

  36. Question 36 of 60 broadcasting Medium

    What is the result of the following code?
    python
    a = np.array([[1], [2], [3]])
    b = np.array([10, 20, 30])
    print((a + b).shape)

  37. Question 37 of 60 broadcasting Medium

    Which pair of array shapes CANNOT be broadcast together?

  38. Question 38 of 60 broadcasting Medium

    What is the output of the following code?
    python
    a = np.array([1, 2, 3])
    print(a + 5)

  39. Question 39 of 60 broadcasting Medium

    Given a of shape (2, 3) and b of shape (3,), what is the shape of a * b?

  40. Question 40 of 60 array operations Medium

    What is the output of the following code?
    python
    arr = np.array([1, 2, 3])
    arr2 = arr
    arr2[0] = 99
    print(arr[0])

  41. Question 41 of 60 arrays vs lists Hard

    Consider the following code:

    Python
    import numpy as np
    lst = [1, 2, 3]
    arr = np.array([1, 2, 3])
    print(lst * 2)
    print(arr * 2)



    What is the output?

  42. Question 42 of 60 arrays vs lists Hard

    A NumPy array stores integers while an equivalent Python list stores the same values. Why does the NumPy array typically consume far less memory?

  43. Question 43 of 60 data types Hard

    What does the following code print?

    Python
    import numpy as np
    arr = np.array([1, 2, 3], dtype=np.int8)
    arr[0] = 130
    print(arr[0])

  44. Question 44 of 60 data types Hard

    Given arr = np.array([1, 2, 3]), which operation returns a new array of type float64 without modifying arr?

  45. Question 45 of 60 data types Hard

    What is the resulting dtype of np.array([True, 2, 3.5])?

  46. Question 46 of 60 array operations Hard

    What does the following print?

    Python
    import numpy as np
    a = np.arange(6).reshape(2, 3)
    b = a.T
    b[0, 0] = 99
    print(a[0, 0])

  47. Question 47 of 60 array operations Hard

    Given a = np.array([10, 20, 30, 40]), what does a[::-1][1:3] return?

  48. Question 48 of 60 array operations Hard

    Consider:

    Python
    import numpy as np
    a = np.array([1, 2, 3, 4, 5])
    mask = a % 2 == 0
    a[mask] = 0
    print(a)



    What is the output?

  49. Question 49 of 60 array operations Hard

    What is the result of np.arange(12).reshape(3, 4)[:, 1::2]?

  50. Question 50 of 60 array operations Hard

    Which statement about np.reshape(a, (-1, 3)) is correct when a has 12 elements?

  51. Question 51 of 60 statistical functions Hard

    For a = np.array([[1, 2], [3, 4]]), what does a.mean(axis=0) return?

  52. Question 52 of 60 statistical functions Hard

    What does np.std(np.array([2, 4, 4, 4, 5, 5, 7, 9])) return (population standard deviation)?

  53. Question 53 of 60 statistical functions Hard

    Given an array containing a np.nan, which function ignores the NaN when computing the mean?

  54. Question 54 of 60 statistical functions Hard

    What is the difference between a.var() and a.var(ddof=1) for a sample array?

  55. Question 55 of 60 statistical functions Hard

    For a = np.array([[1, 5], [3, 2]]), what does np.argmax(a) return?

  56. Question 56 of 60 broadcasting Hard

    Given a of shape (3, 1) and b of shape (1, 4), what is the shape of a + b?

  57. Question 57 of 60 broadcasting Hard

    Which pair of shapes CANNOT be broadcast together?

  58. Question 58 of 60 broadcasting Hard

    What does the following produce?

    Python
    import numpy as np
    a = np.array([[1], [2], [3]])
    b = np.array([10, 20, 30])
    print((a + b).shape)

  59. Question 59 of 60 broadcasting Hard

    To subtract the per-column mean from each element of a (100, 5) array X, which expression works via broadcasting?

  60. Question 60 of 60 broadcasting Hard

    What is the result of the following?

    Python
    import numpy as np
    a = np.array([1, 2, 3])
    b = np.array([[0], [1], [2]])
    print(a * b)

That's unit 4

Answer a few questions and your score shows up here.