AdvancedMultiple choice
A NumPy array is C-ordered. Which loop is faster: summing along rows or along columns?
- AAlong rows, because consecutive elements of a row are adjacent in memory
- BAlong columns, since NumPy is column-major
- CThey are identical, since the same number of elements is touched
- DIt depends only on the array dtype
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
Performance: profiling, vectorising and when to leave Python
Reported in interviews at
More python and data for quants questions
- You test x in container millions of times against a fixed collection of 100,000 ids.Foundation
- A rolling mean, faster, part 1 of 3Foundation
- Profiling shows 60% of runtime in one function.Applied
- A rolling mean, faster, part 2 of 3Applied
- A rolling mean, faster, part 3 of 3Expert
- You add an array of shape (100, 5) to one of shape (5,). What happens?Foundation