Equivalent of "whos" command in NumPy


I am new to Numpy and trying to search for a function to list out the variables along with their sizes (both the matrix dimensions as well as memory usage).

I am essentially looking for an equivalent of the "whos" command in MATLAB and Octave. Does there exist any such command in NumPy?

7/1/2018 7:21:08 PM

Accepted Answer

If you are using IPython, there is a whos command built-in:

In [9]: whos
Variable   Type       Data/Info
a          ndarray    4x4x3: 48 elems, type `int64`, 384 bytes
b          ndarray    100000: 100000 elems, type `int64`, 800000 bytes (781 kb)
np         module     <module 'numpy' from '/Li<...>kages/numpy/__init__.py'>

In general I highly recommend using IPython when doing interactive work in python with numpy/scipy/matplotlib/etc. Fernando Perez and others are actively adding a lot of great features.

10/15/2011 1:22:49 AM

Python has a builtin function dir() which returns the list of names in the current local scope.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow