Long Answer Questions – Introduction to NumPy
(Fixed)
1. Explain the difference between Python lists and NumPy arrays in detail.
Python lists are flexible containers that can hold elements of different data types and their eleme
2. What are the different ways to create NumPy arrays?
Common ways include:
• [Link](list_or_tuple, dtype=...)
• [Link](shape, dtype=...)
• [Link](shape, dtype=...)
• [Link](start, stop, step, dtype=...)
• [Link](start, stop, num)
• [Link](N) for identity matrix
• Random arrays: [Link](), [Link]()
You can also create arrays from files or using functions like [Link](). Specifying dtype controls
3. Explain the attributes of NumPy ndarray objects with examples.
Key attributes:
• ndim — number of array dimensions (axes).
• shape — tuple giving size along each axis, e.g. (3,4).
• size — total number of elements (product of shape elements).
• dtype — data type of elements (e.g. int32, float64, '<U32').
• itemsize — number of bytes per element (e.g. int32 → 4 bytes).
Example:
For array = [Link]([[1,2,3],[4,5,6]], dtype=np.int32):
[Link] == 2, [Link] == (2,3), [Link] == 6, [Link] == 'int32', [Link] == 4
4. Discuss indexing and slicing operations in NumPy arrays with examples.
Indexing accesses single elements via zero-based indices: a[i] for 1-D or a[i,j] for 2-D. Slicing u
• a[1:4] — elements at indices 1,2,3.
• a[::-1] — reverse the array.
• For 2-D: a[0:2, 1:3] selects rows 0–1 and columns 1–2. Omitting a slice (:) means the full range
5. Explain arithmetic operations on NumPy arrays with examples.
NumPy supports vectorized element-wise arithmetic (+, -, *, /, **, %). Arrays must be shape-compati
A = [Link]([1,2,3])
B = [Link]([4,5,6])
A + B -> [5,7,9]
Matrix multiplication uses '@' (A @ B) or [Link](A,B). Broadcasting lets arrays of different shapes
6. What are concatenation and splitting in NumPy?
Concatenation joins arrays along a specified axis using [Link]((a,b), axis=...). For exampl
7. Describe reshaping of arrays and its importance.
reshape() changes the view of an array to a new shape without changing data order. The total number of
elements must remain the same. Example: [Link](12).reshape(3,4). Reshaping is crucial to prepare
data for matrix algebra, machine learning models, broadcasting, and visualization.
8. Explain how NumPy performs statistical operations on arrays.
NumPy provides fast aggregated functions: max(), min(), sum(), mean(), std(), var(), median (via np
9. How can you load and save data using NumPy functions?
Use [Link]() for well-formed numeric text files and [Link]() to handle missing values an
10. Explain the case study based on the Iris dataset using NumPy.
The Iris case study demonstrates practical steps: load data ([Link] with skip_header and del
Notes on fixes made
• Fixed typos and inconsistent capitalization.
• Improved and clarified code examples and descriptions.
• Added missing array-creation methods ([Link], [Link], random functions).
• Clarified itemsize and dtype examples.
• Recommended binary save/load ([Link]) as alternative to text files.
If you still see specific errors in the PDF, tell me which page/line and I'll correct them.