NumPy Theoretical Questions. Flashcards
(10 cards)
What is the primary function of the NumPy library?
NumPy is used for creating and manipulating homogeneous n-dimensional arrays and performing mathematical operations like linear algebra and statistical analysis (Page 11)
In which programming language is NumPy primarily written, and why is this significant?
NumPy is written in C, which allows for compiler optimization and faster execution (Page 11).
What does the shape property of a NumPy array return?
It returns a tuple representing the dimensions of the array, e.g., (4,) for a 1D array with 4 elements (Page 13).
How does np.arange() differ from np.linspace() in creating arrays?
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).
What is the purpose of the np.random.rand() function?
It generates random numbers from a uniform distribution between 0 and 1, with the specified shape (Page 19).
What is conditional selection in NumPy, and what is it also known as?
It filters elements based on a condition, also known as Boolean Indexing or Boolean Masking (Page 27).
What does the np.concatenate() function do with NumPy arrays?
It combines arrays along a specified axis without requiring a common column (Page 28).
How can you sort a NumPy array in descending order?
Use np.sort(arr)[::-1] to sort in ascending order and then reverse the result (Page 30).
What does the reshape() function do to a NumPy array?
It changes the array’s dimensions while preserving its data, e.g., converting a 1D array to a 2D array (Page 31).
Name two statistical operations that can be performed on a NumPy array.
Mean and median (Page 11).