Skip to Content
Numerical Computing with Python
book

Numerical Computing with Python

by Pratap Dangeti, Allen Yu, Claire Chung, Aldrin Yim
December 2018
Beginner to intermediate
682 pages
18h 1m
English
Packt Publishing
Content preview from Numerical Computing with Python

There's more...

It is possible to complete this recipe in one long line of code chaining the indexing operator with an anonymous function. This little trick removes the need for step 10. We can time the difference between the direct idxmax method and our manual effort in this recipe:

>>> %timeit college_n.idxmax().values1.12 ms ± 28.4 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)>>> %timeit college_n.eq(college_n.max()) \                                  .cumsum() \                                  .cumsum() \                                  .eq(1) \                                  .any(axis='columns') \                                  [lambda x: x].index5.35 ms ± 55.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

Our effort is, unfortunately, five times as slow as the built-in idxmax pandas method but regardless of its performance regression, many creative and practical solutions ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Numerical Computing with NumPy

Mastering Numerical Computing with NumPy

Umit Mert Cakmak, Tiago Antao, Mert Cuhadaroglu

Publisher Resources

ISBN: 9781789953633OtherOtherErrata Page