Open In App

NumPy who() Method | Print Arrays in Dictionary

Last Updated : 05 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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

Python3




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:

array in dictionary

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.

Python3




# creating numpy ndarrays
x = np.arange(20)
y = np.ones(5)
z = np.zeros(10)
  
# function called without passing any argument
np.who()


Output:

ndarray from globals() dictionary



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads