Reputation: 11
Why am I having this error
import numpy as np
np.array([1,2,3,4])
NameError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_2304/609253908.py in ----> 1 np.array([1,2,3,4])
NameError: name 'np' is not defined
Upvotes: 0
Views: 1611
Reputation: 6359
Your error code says that np.array([1, 2, 3, 4])
is in line 1
so you are trying to use it before importing, you need to import numpy
first, as shown in your question.
Upvotes: 3
Reputation: 34
You can just go with numpy
import numpy
numpy.array([1,2,3,4])
Have you installed or updated numpy? Try this once in your terminal.
>>> pip install numpy
Upvotes: -1