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

标签 python numpy google-colaboratory

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

相关文章:

python - 将二维字典转换为 numpy 矩阵

python - "Invalid parameter type"(numpy.int64) 使用 executemany() 插入行时

python - 运行 'conda init'后关闭并重启shell

python - 预训练模型所需的标准化 (PyTorch)

python - Numpy 数组多个掩码

javascript - django 上找不到页面(404)错误

matplotlib - 如何在 Google Colab 中使用 matplotlib 绘制交互式可绘制图像?

python - Google CoLab:如何使用opencv从我的Google驱动器读取数据?

python - IronPython - 有没有办法从数据库加载 python 脚本或从字符串资源嵌入?

python - 在条件下填充 df 的行