02 / 02

What is the main object in NumPy?

Difficulty: 2/10
ndarray, array creation, memory layout

ndarray (N-dimensional array) is the core data structure. In NumPy, the idea of array is generalized to an arbitrary number of dimensions, and so the fundamental array class is called ndarray: it represents an “N-dimensional array”.

Scenario Questions

0-2 years experience

  1. 1How would you create a 2‑D ndarray of zeros with shape (3, 4) using NumPy?
  2. 2Given a Python list of numbers, show how you would convert it to an ndarray and compute its mean.
  3. 3What happens if you try to store string values in an ndarray that was created with a float dtype?

2-5 years experience

  1. 1You receive an ndarray that unexpectedly contains NaNs after a computation; how would you investigate whether dtype casting caused the issue?
  2. 2A function in a larger codebase expects a list but you have an ndarray; how would you resolve the type mismatch and why?
  3. 3Explain why a vectorized operation on an ndarray might run slower than expected; what factors could be responsible?

5-8 years experience

  1. 1Design a data‑processing pipeline that reads large CSV files into ndarrays, processes them, and writes results while keeping memory usage low; what trade‑offs would you consider?
  2. 2In a machine‑learning training loop that repeatedly creates temporary ndarrays, how would you optimise memory and speed—using in‑place operations versus copying?
  3. 3If you need to share ndarrays across processes on a multi‑node cluster, what mechanisms would you choose and what pitfalls must you avoid?

8+ years experience

  1. 1Your team is migrating legacy code that uses nested Python lists for matrix math to NumPy; outline a migration plan that minimises risk and preserves performance.
  2. 2When building a cross‑team analytics platform, how would you standardise ndarray usage to avoid versioning and dtype inconsistencies?
  3. 3Discuss the long‑term maintenance implications of building a distributed system that relies heavily on ndarrays as the core data structure; what alternatives or abstractions might you evaluate?

Follow-up Questions

  • How does an ndarray differ from a plain Python list in terms of memory and performance?
  • What impact does the dtype of an ndarray have on arithmetic operations?
  • Can you explain how broadcasting works with ndarrays?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.