If Python and PIP are already installed on your system, installing NumPy is a straightforward process.
Use the following command to install it:
C:\Users\Your Name>pip install numpy |
If this command fails, consider using a Python distribution that comes with NumPy pre-installed, such as Anaconda or Spyder.
After installing NumPy, you can import it into your application by using the import keyword:
import numpy |
NumPy is now imported and ready for use.
import numpy arr = numpy.array([1, 2, 3, 4, 5]) print(arr) |
NumPy is commonly imported using the alias np.
In Python, an alias is an alternate name used to refer to the same object or entity. |
Use the as keyword to create an alias when importing:
import numpy as np |
You can now refer to the NumPy package as np instead of numpy.
import numpy as np arr = np.array([1, 2, 3, 4, 5]) print(arr) |
The version number is stored in the __version__ attribute.
import numpy as np print(np.__version__) |