當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python numpy.who()用法及代碼示例

numpy.who(vardict=None) 函數打印給定字典中的 Numpy ndarray。如果沒有傳入字典或 vardict 為 None,則在 globals() 字典中打印 NumPy 數組。

參數:

vardict:可能包含 ndarray 的字典。默認為 globals()。

返回值:

out:

注意:它打印出 vardict 中存在的所有 ndarray 的名稱、形狀、字節和類型,但不返回任何內容。

範例1:在此示例中,字典作為參數傳遞給 numpy.who() 函數。

Python3


# import the numpy module as np
import numpy as np
  
# dictionary containing numpy ndarrays
gfg = {'arr_1':np.arange(3), 'arr_2':np.arange(6),
       'name':'some text', 'number':34523}
  
# passing the dict as argument
np.who(gfg)

輸出:

範例2:在此示例中,沒有參數傳遞給 numpy.who() 函數,因此它在 globals() 字典中打印 ndarray。

Python3


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

輸出:

相關用法


注:本文由純淨天空篩選整理自mohanrajnambe大神的英文原創作品 numpy.who() function in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。