Getting Started with Python NumPy

In This Article You Will Learn About Python Numpy

Python NumPy – Before moving ahead, let’s know a little bit about Python Tutorial

NumPy Introduction

NumPy: It stood for Numerical Python and was created in 2005 by Travis Oliphant. It is an open-source Python library that is free to use. In Python, NumPy is used for working with arrays.

NumPy: Why?

Lists in Python serve the same purpose as arrays but are slower to process.

NumPy is a Python list that provides array objects that are up to 40 to 50x faster than the traditional Python lists.

NumPy’s array object is called “ndarray” and offers many supporting functions that make working in ndarray easy.

What makes NumPy faster than lists?

NumPy arrays can be accessed and manipulated very fastly because they are kept in a single place in memory, unlike lists.

What Language is NumPy written?

NumPy, a Python library, is partially written in Python. However, most parts require fast computations written in C or C++.

NumPy Installation

Installing NumPy on a system that already has Python and PIP is easy.

This command will install it:

pip install numpy

If the command fails, you can try another python distribution with NumPy installed, such as Anaconda.

Import NumPy

After NumPy has been installed, you can import it into your applications by adding the “import” keyword:

import numpy

Let’s ahead with NumPy as it is imported now.

Example – Creating an array of five elements.

import numpy
Array = numpy.array([1, 2, 3, 4, 5])

print(Array)
python-numpy

As a result, it is clear that it returned an array.

NumPy as np

NumPy can usually be imported under the np name.

Alias in Python: It is an alternate name for the same thing.

When you import, create an alias using the ‘as‘ keyword.

import numpy as np

As had been noticed that Numpy is imported as np.

After referring to NumPy as np, now NumPy can be identified as np.

Example – importing numpy as np.

import numpy as np
Array = np.array([1, 2, 3, 4, 5])

print(Array)
python-numpy

As a result, it is clear that it returned an array.

The NumPy Version

The version string is stored under the __version__ attribute

import numpy as np
print(np.__version__)
python-numpy

As shown above, it returned the current version of Numpy

If you find anything incorrect in the above-discussed topic and have any further questions, please comment below.

Like us on

Recent Post

Popular Post

Top Articles

Archives
Categories

Share on