# My most used NumPy/SciPy functions

2013-01-04

I analyzed my recent Python scripts, and it appears that the most used NumPy/SciPy symbols are:

`asarray`

by a large margin`linspace`

, three times less often than`asarray`

`mean`

`dot`

`sqrt`

`roll`

`hstack`

`float32`

(that's not a function, but a type)`loadtxt`

`linalg.norm`

`arange`

(I use it four times less often than`linspace`

)`array`

(copy-by-default, much less used than`asarray`

)`where`

`diff`

`cumsum`

`savetxt`

(two times less often than`loadtxt`

)`max`

`cross`

`sin`

`ones`

Overall, the most used functions

- convert anything to array (mostly lists and nested lists)
- do simple file input-output (
`loadtxt`

,`savetxt`

) - construct new arrays from the existing blocks (
`hstack`

,`roll`

...) and default arrays (`ones`

,`zeros`

,`linspace`

,`arange`

...) - do basic linear algebra (
`dot`

,`cross`

,`norm`

) - make common reductions (
`mean`

,`cumsum`

,`max`

, ...) - broadcast function application (
`sqrt`

,`sin`

, ...) - define inter-element relations (
`roll`

,`diff`

)

This may be useful to know when designing a custom array-like API (I still wish I had time to write a Clojure wrapper around Commons Math).

I counted only qualified and explicit imports ("import numpy as np", "from nump import foo"). I didn't count scripts which use `from ... import *`

. That's too much work for grep and sed. I also didn't count use of array object's methods. This would require static analysis of Python code.

Do you know tools for such an analysis?