【发布时间】:2021-12-31 04:55:02
【问题描述】:
我正在尝试编写一个简单的 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
如何获得函数文档?
【问题讨论】:
-
你的意思是
help(np.info(np.add))?help(<topic>)通常会获取给定“主题”的简短版 python 文档 -
@chickitychinachinesechicken 实际上
help(np.add)返回的np.add函数的文档过于广泛。我在这里找到了正确的解决方案 w3resource.com/python-exercises/numpy/basic/… 但它不起作用 -
np.info包括print。它不返回任何东西,或者更确切地说返回None。有一些函数可以返回格式化的字符串,然后您可以打印,np.info不是其中之一。 -
在笔记本上做一个
np.info??看看这个函数实际上做了什么——打印在最后。
标签: python numpy google-colaboratory