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?
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.
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.
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.
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.
Python has a builtin function dir()
which returns the list of names in the current local scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With