我正在嘗試撰寫一個簡單的 NumPy 程式,以使用 google colab notebook 獲取有關添加功能的幫助。
解決辦法是:
print(np.info(np.add))
它應該回傳:
add(x1, x2[, out])
Add arguments element-wise.
Parameters
----------
x1, x2 : array_like
The arrays to be added. If ``x1.shape != x2.shape``, they must be
broadcastable to a common shape (which may be the shape of one or
the other).
Returns
-------
add : ndarray or scalar
The sum of `x1` and `x2`, element-wise. Returns a scalar if
both `x1` and `x2` are scalars.
Notes
-----
Equivalent to `x1` `x2` in terms of array broadcasting.
Examples
--------
>>> np.add(1.0, 4.0)
5.0
>>> x1 = np.arange(9.0).reshape((3, 3))
>>> x2 = np.arange(3.0)
>>> np.add(x1, x2)
array([[ 0., 2., 4.],
[ 3., 5., 7.],
[ 6., 8., 10.]])
None
但我只得到:
None
我如何獲得功能檔案?
uj5u.com熱心網友回復:
numpy.info不回傳資訊字串。它直接列印到標準輸出或您指定的另一個類似檔案的物件。
IPython 筆記本覆寫sys.stdout,但如果它在 numpy.info抓取sys.stdout用作默認引數后這樣做,則numpy.info最終會嘗試寫入舊的標準輸出。
告訴numpy.info顯式列印到新的標準輸出。此外,print除非您確實None出于某種原因確實想列印一個不相關的值,否則您不應該回傳值。
numpy.info(numpy.add, output=sys.stdout)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/361611.html
上一篇:我如何撰寫一個python單行程式來創建檔案中所有單詞的串列?[復制]
下一篇:CPPythonLogicConfusiononModernArt(BronzeUSACO2017USOpenp.3)
