QuizLander
← Tous les quiz publics

Python — NumPy: arrays & vectorized computation

par Jude · 23/05/2026 · 117 vues · 0 partages

Creating ndarrays, dtypes, shape, broadcasting, advanced indexing, aggregations, and performance. 20 questions.
20
Questions
🇬🇧 English
Langue
Moyen
Difficulté
Démarrer le quiz (invité ou compte)
Partager comme image

Les questions du quiz

  1. 1. What is the main difference between a Python list and a numpy.ndarray?
    1. None
    2. ndarray is typed, contiguous in memory, and supports vectorized ops; lists are heterogeneous and slower
    3. Lists are faster for numeric work
    4. ndarray is a subclass of list
  2. 2. What is a.shape?
    import numpy as np
    a = np.array([[1, 2, 3], [4, 5, 6]])
    print(a.shape)
    1. (2, 3)
    2. (3, 2)
    3. (6,)
    4. (2, 3, 1)
  3. 3. What does this print?
    a = np.arange(6).reshape(2, 3)
    print(a.sum(axis=0))
    1. [3 5 7]
    2. [3 12]
    3. [0 1 2 3 4 5]
    4. 15
  4. 4. What is the broadcast output shape?
    a = np.array([[1], [2], [3]])     # shape (3, 1)
    b = np.array([10, 20, 30])         # shape (3,)
    print((a + b).shape)
    1. (3,)
    2. (3, 3)
    3. (1, 3)
    4. ValueError
  5. 5. Default dtype of np.array([1, 2, 3]) on a 64-bit OS?
    1. int8
    2. int32
    3. int64
    4. float64
  6. 6. What is a after this?
    a = np.array([1, 2, 3, 4, 5])
    b = a[1:4]
    b[0] = 99
    print(a)
    1. [1 2 3 4 5]
    2. [1 99 3 4 5]
    3. [1 99 99 99 5]
    4. Error
  7. 7. What does boolean indexing produce?
    a = np.array([10, 20, 30, 40])
    print(a[a > 15])
    1. [10 20 30 40]
    2. [20 30 40]
    3. [False True True True]
    4. Error
  8. 8. Difference between np.dot(a, b) and a * b for matrices?
    1. None
    2. np.dot is matrix multiplication; * is element-wise (Hadamard) product
    3. * is faster
    4. np.dot is deprecated
  9. 9. What does this return?
    a = np.zeros((2, 3), dtype=np.int32)
    print(a.dtype, a.nbytes)
    1. int32 12
    2. int32 24
    3. int64 24
    4. float64 48
  10. 10. Which generates 100 evenly spaced values from 0 to 1 inclusive?
    1. np.arange(0, 1, 100)
    2. np.linspace(0, 1, 100)
    3. np.range(0, 1, 100)
    4. np.logspace(0, 1, 100)
  11. 11. What does this print?
    a = np.array([1, 2, np.nan, 4])
    print(a.sum(), np.nansum(a))
    1. 7.0 7.0
    2. nan 7.0
    3. 7.0 nan
    4. Error
  12. 12. How do you reshape (12,) to (3, 4) without copying when possible?
    1. a.reshape(3, 4)
    2. a.resize(3, 4) only
    3. np.copy(a).reshape(3, 4)
    4. Impossible without copy
  13. 13. What is the output?
    a = np.array([[1, 2], [3, 4]])
    print(a.T)
    1. [[1 2] [3 4]]
    2. [[1 3] [2 4]]
    3. [[4 3] [2 1]]
    4. Error
  14. 14. Asymptotic complexity of standard (n, n) @ (n, n)?
    1. O(n)
    2. O(n²)
    3. O(n³)
    4. O(n log n)
  15. 15. What does this print?
    rng = np.random.default_rng(42)
    print(rng.integers(0, 10, size=3))
    1. Three reproducible ints in [0, 10)
    2. Three floats between 0 and 10
    3. Three reproducible ints in [0, 10] (inclusive)
    4. Error — default_rng does not exist
  16. 16. Which expression sets negatives to 0?
    1. a[a < 0] = 0
    2. a.replace(< 0, 0)
    3. a.zero_negatives()
    4. np.abs(a)
  17. 17. Difference between a.flatten() and a.ravel()?
    1. None
    2. flatten always copies; ravel returns a view if possible
    3. ravel is slower
    4. flatten only works on 1D
  18. 18. What is r?
    a = np.array([[1, 2, 3], [4, 5, 6]])
    r = a[:, [2, 0]]
    print(r)
    1. [[3 1] [6 4]]
    2. [[1 3] [4 6]]
    3. [[2 0] [5 3]]
    4. Error
  19. 19. Best way to read/write arrays in NumPy's native binary format?
    1. np.save / np.load
    2. pickle.dump / pickle.load
    3. json.dump
    4. open(..., "wb") + str(a)
  20. 20. Why vectorize instead of looping in Python for elementwise math?
    1. No reason
    2. Vectorized ops run in C/SIMD instead of the Python interpreter, often 10×–100× faster
    3. Python loops are faster in NumPy
    4. Vectorizing uses more memory and is always slower
Répondre aux questions et voir mon score

Commentaires

Connecte-toi pour commenter.

Chargement…