Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of "whos" command in NumPy

Tags:

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?

like image 601
user996357 Avatar asked Oct 15 '11 00:10

user996357


People also ask

What is equivalent to Whos in Python?

Python has a builtin function dir() which returns the list of names in the current local scope. Show activity on this post. This more or less works as who equivalent.

How do you use who in Python?

You can use the %whos command at any time to see what variables you have created and what modules you have loaded into the computer's memory. As this is an IPython command, it will only work if you are in an IPython terminal or the Jupyter Notebook.

What is NumPy Matlab?

NumPy performs operations element-by-element, so multiplying 2D arrays with * is not a matrix multiplication – it's an element-by-element multiplication. (The @ operator, available since Python 3.5, can be used for conventional matrix multiplication.) MATLAB numbers indices from 1; a(1) is the first element.


2 Answers

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.

like image 129
JoshAdel Avatar answered Sep 27 '22 21:09

JoshAdel


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

like image 38
cyborg Avatar answered Sep 27 '22 21:09

cyborg