'Error in Jupyter notebook even after importing the required library

I'm getting an NameError in jupyter notebook even after importing numpy as np. Any idea how to go about it will be appreciated

%matplotlib inline
%config InlineBackend.figure_format = 'retina'

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 1, 300)
for i in range(2, 6, 2):
    plt.plot(x, np.sin(np.pi*x)*np.sin(2*i*np.pi*x))

Error


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 x = np.linspace(0, 1, 300)
      2 for i in range(2, 6, 2):
      3     plt.plot(x, np.sin(np.pi*x)*np.sin(2*i*np.pi*x))

NameError: name 'np' is not defined



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source