Examples missing import numpy as np?
See original GitHub issueHi
a bunch of examples seem to be missing import numpy as np. At least for me they throw NameError: name 'np' is not defined.
Following examples seem to be missing import numpy as np (non exhaustive):
- scipy.signal.spectrogram
- scipy.signal.periodogram
- scipy.signal.welch
scipy.__version__ gives 1.4.1. However, the examples seem to be the same in the current master.
Maybe I am missing something? Any help is appreciated! Thanks 😃
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:48 (43 by maintainers)
Top Results From Across the Web
import NumPy as np ImportError No module named ... - Edureka
Hi Guys,. I have NumPy installed in my computer. But still I am getting this below error. import NumPy as np ImportError: No...
Read more >ModuleNotFoundError: No module named numpy as np
I am using Visual Studio Code and try to 'import cv2', but I see an error.
Read more >How to Fix: No module named NumPy - GeeksforGeeks
In this article, we will discuss how to fix the No module named numpy using Python. Numpy is a module used for array...
Read more >How to Fix: No module named numpy - Statology
This error occurs when Python does not detect the NumPy library in your current environment. This tutorial shares the exact steps you can...
Read more >[Fixed] ModuleNotFoundError: No module named 'numpy'
Example : Suppose that you are trying to import the Numpy library and print an array. However you get an ImportError: ModuleNotFoundError: No...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I don’t have a horse in this race, but I wanted to mention an alternative that came up on https://github.com/networkx/networkx/issues/5720
We could ask IPython/Jupyter whether they could detect common missing names and give an error message after a NameError with some guidance, such as:
This is a best-of-both-worlds type scenario, where we don’t need to repeat the same imports over and over in the docstrings, but users get helpful feedback for common package imports (
np,sp,plt,pd,nx, etc).Some docstrings have multiple examples, but these are often interspersed with lots of text. Should a numpy import happen once in a docstring, or with each example (as previous comments suggest)? The latter is bloat-worthy.
numpy is ubiquitous, so knowing what
np.summeans without the import being included in a docstring doesn’t seem like an egregious act. Even then it’s only a websearch away. A single websearch is small fry compared to ‘ugliness’ caused by adding an explicit numpy import.Besides, there are inline code snippets in multiple places that implicitly use np:
np.std(pop) <= atol + tol * np.abs(np.mean(population_energies))is present in the docstring, do they deserve an import?In a typical interpreter session (Python/IPython) you only need to do the import once (18 characters worth), and it lasts for the duration of the session. I would argue that the cost of typing that is miniscule compared to the cost incurred by adding the numpy import to every example.