AppliedMultiple choice
You take b = a[[0, 2, 4]] from a NumPy array a and then set b[0] = 99. What happens to a?
- A
a[0]becomes 99, because indexing always returns a view - B
ais unchanged - CNumPy raises an error because
bis read-only - D
a[0],a[2]anda[4]all become 99
The worked solution is in Premium
The answer, the full working and the one idea to take away – for this and all 1,322 questions in the bank. Answer it in practice and your working is marked, with a known mistake named when you make one.
Learn the method
Reported in interviews at
More python and data for quants questions
- You add an array of shape (100, 5) to one of shape (5,). What happens?Foundation
- How much memory does a 5,000 × 5,000 float64 NumPy array use, in megabytes?Foundation
- How many elements does the result of adding NumPy arrays of shapes (3, 1) and (1, 4) have?Foundation
- What is the length of np.arange(10).reshape(2, 5).sum(axis=0)?Foundation
- Shapes in a returns matrix, part 1 of 3Foundation
- You slice a[::2] and then modify the result. What happens to a?Applied