CHAPTER 03
Beginner
NumPy Arrays Basics
Updated: May 18, 2026
5 min read
# CHAPTER 3
NumPy Arrays Basics
1. Chapter Introduction
Thendarray (N-dimensional array) is NumPy's core. It stores elements of the same type in a contiguous memory block — enabling C-speed computation from Python. Understanding arrays is the foundation of all numerical computing in Python.
2. Creating Arrays
python
3. Array Creation Functions
python
4. Array Attributes
python
5. Data Types
python
6. Reshape and Resize
python
7. Mini Project: Matrix Generator
python
8. Common Mistakes
-
Mutable list vs immutable shape: Once created, a NumPy array's
dtypeis fixed. Adding a float to an int array converts automatically but may lose precision.
-
reshapevsresize:reshapereturns a new view with different shape.resizemodifies in-place and can change total element count.
9. MCQs
Question 1
np.zeros((3,4)) creates?
Question 2
arr.ndim returns?
Question 3
arr.shape for a 2x3 array?
Question 4
np.arange(0, 10, 2) produces?
Question 5
arr.astype(np.float32) does?
Question 6
arr.reshape(4, -1) where arr has 12 elements?
Question 7
arr.flatten() returns?
Question 8
np.linspace(0, 1, 5) produces?
Question 9
arr.nbytes returns?
Question 10
np.eye(3) creates?
10. Interview Questions
-
Q: What is the difference between
np.zeros,np.ones, andnp.empty?
- Q: Why must all elements in a NumPy array have the same dtype?
11. Summary
NumPy'sndarray provides multi-dimensional array storage with fixed dtype, enabling C-speed computation. Key attributes: ndim, shape, size, dtype, nbytes. Array creation functions (zeros, ones, arange, linspace, eye) cover every common use case.