The who() function of the NumPy library prints the NumPy ndarray in the given dictionary of the current module.
If no dictionary is passed in or vardict is None then it prints NumPy arrays in the globals() dictionary.
Example
import numpy as np
# dictionary containing numpy ndarrays gfg = { 'arr_1' : np.arange( 3 ), 'arr_2' : np.arange( 6 ),
'name' : 'some text' , 'number' : 34523 }
np.who(gfg) |
Output:
Syntax
Syntax: numpy.who(vardict=None)
Parameters
- vardict: A dictionary possibly containing ndarrays. Default is globals().
Returns
- out: None
Note: It prints out the name, shape, bytes, and type of all of the ndarrays present in Vardict but returns none.
How to Print ndarrays from Python Dictionary?
You can print NumPy arrays from a Python dictionary containing ndarrays using who method of NumPy library.
Let us understand it better with an example:
Example: Print the NumPy arrays in the given Dictionary
In this example, no argument is passed to the numpy.who() function so it prints ndarray in globals() dictionary.
# creating numpy ndarrays x = np.arange( 20 )
y = np.ones( 5 )
z = np.zeros( 10 )
# function called without passing any argument np.who() |
Output: