NumPy Theoretical Questions. Flashcards

(10 cards)

1
Q

What is the primary function of the NumPy library?

A

NumPy is used for creating and manipulating homogeneous n-dimensional arrays and performing mathematical operations like linear algebra and statistical analysis (Page 11)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In which programming language is NumPy primarily written, and why is this significant?

A

NumPy is written in C, which allows for compiler optimization and faster execution (Page 11).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the shape property of a NumPy array return?

A

It returns a tuple representing the dimensions of the array, e.g., (4,) for a 1D array with 4 elements (Page 13).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does np.arange() differ from np.linspace() in creating arrays?

A

np.arange() creates an array with a specified step size, excluding the stop value, while np.linspace() creates an array with a specified number of evenly spaced elements, including the stop value (Page 17).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of the np.random.rand() function?

A

It generates random numbers from a uniform distribution between 0 and 1, with the specified shape (Page 19).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is conditional selection in NumPy, and what is it also known as?

A

It filters elements based on a condition, also known as Boolean Indexing or Boolean Masking (Page 27).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the np.concatenate() function do with NumPy arrays?

A

It combines arrays along a specified axis without requiring a common column (Page 28).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can you sort a NumPy array in descending order?

A

Use np.sort(arr)[::-1] to sort in ascending order and then reverse the result (Page 30).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the reshape() function do to a NumPy array?

A

It changes the array’s dimensions while preserving its data, e.g., converting a 1D array to a 2D array (Page 31).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Name two statistical operations that can be performed on a NumPy array.

A

Mean and median (Page 11).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly