I'm trying to learn how numpy arrays works in python to accomplish some tasks , but I encountered a problem at a very early basic level .
I tried this very simple script :
import numpy
v = array([1,2,3,4])
type(v)
but I got this error :
Traceback (most recent call last):
File "C:\Users\Al-Hammad\Desktop\Test Sample\whatever.py", line 5, in <module>
v = array([1,2,3,4])
NameError: name 'array' is not defined
Tool completed with exit code 1
I have tried the following solutions but None of them worked out the problem.
1.One might say that I don't have numpy installed , I tried this and it's already there:
try: import
numpy
print("Numpy is already there !")
except ImportError: p
rint("Numpy is not installed")
Numpy is already there !
Tool completed successfully
2.The file name is whatever.py , so it's not a matter of duplicate module's names as some threads suggests.
3.numpy is written correctly , so it's not a syntax error or a typo !!
4.I tried this also:
import numpy
import array
from array import array
v = numpy.array([1,2,3,4])
Traceback (most recent call last): File "C:\Users\Al-Hammad\Desktop\Test Sample\whatever.py", line 6, in v = numpy.array([1,2,3,4]) AttributeError: 'module' object has no attribute 'array'
Tool completed with exit code 1
What am I doing wrong here ? Any help would be appreciated .
Edit:
@Ffisegydd...Python can see the numpy package , but it can't access it's contents,when I looked into programs and features in the control panel it wasn't there , but it's contents resides in the site_packages folder where python installed !!
Could it have been uninstalled in any way during system update ?
import numpyyou would never automatically get access to any names other thannumpy. This is nothing to do with numpy itself, but a basic principle of Python.