Installing NumPy
If you already have Python and PIP installed on your system, installing
NumPy is straightforward. Simply open your command prompt or terminal and
run:
pip install numpy
If you encounter any issues during installation, consider using a Python
distribution that comes with NumPy pre-installed, such as Vscode,
Anaconda or Spyder. These environments are beginner-friendly
and come bundled with popular scientific libraries.
Importing NumPy
After installation, you can start using NumPy in your Python projects by
importing it:
With this line, NumPy is ready to use and you can start working with
powerful array operations and mathematical functions it offers.
Program:
Output:
[1 2 3 4 5]
Try it YourselfImporting NumPy as `np`
In the Python community, it's common practice to import NumPy using the
alias `np`. This makes your code cleaner and easier to read.
What is an alias?
An alias is an alternative name used to refer to the same module. In
Python, you can create an alias using the `as` keyword.
How to import NumPy with an alias:
Now, instead of typing `numpy` every time, you can simply use `np`. This is
especially helpful when you're working with a lot of NumPy functions.
Creating a NumPy array
[1 2 3 4 5]
Try it YourselfChecking the NumPy Version
To find out which version of NumPy you're using, you can check the
`__version__` attribute.
This will print the installed version of NumPy, such as
`1.26.4`.