gpt4 book ai didi

python - Numpy:获取有关添加功能的帮助

转载 作者:行者123 更新时间:2023-12-05 03:34:53 25 4
gpt4 key购买 nike

我正在尝试编写一个简单的 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

但我只得到:

如何获取函数文档?

最佳答案

numpy.info 不返回信息字符串。它直接打印到标准输出或您指定的其他类似文件的对象。

IPython notebook 会覆盖 sys.stdout,但如果这样做, numpy.info 获取 sys.stdout 用作默认参数,然后 numpy.info 最终尝试写入旧的标准输出。

告诉 numpy.info 显式打印到新的标准输出。此外,您不应打印 返回值,除非出于某种原因您确实想要打印不相关的None

numpy.info(numpy.add, output=sys.stdout)

关于python - Numpy:获取有关添加功能的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70051391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com