Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Numpy: Get help on the add function

I am trying to write a simple NumPy program to get help on the add function using google colab notebook.

The solution is:

print(np.info(np.add))

It should return:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

But I get only:
None

How could I get the function documentation?

>Solution :

numpy.info doesn’t return an info string. It prints straight to stdout, or another file-like object you specify.

An IPython notebook overrides sys.stdout, but if it does so after numpy.info grabs sys.stdout to use as a default parameter, then numpy.info ends up trying to write to the old stdout.

Tell numpy.info to print to the new stdout explicitly. Also, you shouldn’t print the return value unless you actually do want to print an irrelevant None for some reason.

numpy.info(numpy.add, output=sys.stdout)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading