Unit 6: Introduction to NumPy - Subjective Questions

ECAP776 • Practice Questions with Detailed Answers

20 questions

1

Define a NumPy array. Explain how it differs from a Python list with respect to data type, memory usage, and supported operations.

2

Compare the result of multiplication and addition operations on Python lists and NumPy arrays using suitable examples.

3

Explain the meaning and importance of the NumPy array attributes ndim, shape, size, and dtype.

4

Why are NumPy arrays generally more suitable than Python lists for large numerical computations? Discuss vectorization and memory efficiency.

5

Describe homogeneous storage and type promotion in NumPy arrays. What happens when integers and floating-point values are supplied together?

6

Explain how np.zeros(), np.ones(), and np.full() create arrays. Give examples of creating arrays with shape .

7

Describe np.empty(). How does it differ from np.zeros(), and why must its contents not be treated as initialized values?

8

Explain the syntax and behavior of np.arange(). Determine the output of np.arange(2, 12, 3) and state an important limitation for floating-point steps.

9

Compare np.arange() and np.linspace(). When should each routine be used?

10

Derive the spacing produced by np.linspace(a, b, n) when the endpoint is included. Then find the output of np.linspace(0, 1, 5).

11

Explain the purpose of np.eye() and np.identity(). Create a identity matrix and describe a case where np.eye() is more flexible.

12

Describe how a one-dimensional sequence created with an array creation routine can be converted into a multidimensional array using reshape(). State the necessary size condition.

13

Explain how NumPy arrays are created from existing Python lists and tuples. Include examples of one-dimensional and two-dimensional input.

14

Distinguish between np.array() and np.asarray() when converting existing data, especially when the input is already a NumPy array.

15

Describe the purpose of np.fromiter() and np.frombuffer() for creating arrays from existing data. Mention one important consideration for each routine.

16

Explain positive and negative indexing in a one-dimensional NumPy array. For a = np.array([10, 20, 30, 40, 50]), find a[1], a[-1], and a[-3].

17

Explain NumPy slicing using the general form start:stop:step. Determine a[1:7:2] and a[::-1] for a = np.arange(8).

18

Describe indexing and slicing in a two-dimensional NumPy array. For a = np.arange(12).reshape(3, 4), determine a[1, 2], a[:, 1], and a[0:2, 2:4].

19

Explain the difference between a basic slice view and an independent copy in NumPy. Demonstrate how modifying a slice can affect the original array.

20

Compare basic slicing, integer array indexing, and Boolean indexing in NumPy. Use examples and explain whether the result usually shares data with the source.