Education

Quick Dive In Python’s NumPy for Data Science

Pinterest LinkedIn Tumblr

Python NumPy is one of the most used libraries in the world of Data Science. Travis Oliphant created NumPy in 2005 as an open source project which means you can use it freely. Its a library that supports multi-dimensional arrays and matrices. It also has a large collection of high level scientific and mathematical functions to operate on these arrays. Python NumPy also have functions for linear algebra and fourier transforms that is used many times in data science.

Why should we use NumPy arrays?

There are many reasons why we should use NP arrays one particularly being it uses less memory to store data. The NP arrays takes less amount of memory as compared to its python brother lists. Another reason why we should use NP instead of lists is Its really helpful when it comes to creating n-dimensional arrays which allows you to create matrix and tensors in no time. To know more why you shoud you use NP I suggest you read Deepak K Gupta blog on A hitchhiker guide to python NP Arrays.

The source code of its library is available Here if you want to know more.

Now we have a little introduction into the subject, lets begin our little dive.

 

Import NumPy and use NP arrays:

importnp

So we have created 2 np arrays using these methods:

result1

You can also pass a multi-dimensional array to create a np array:

multidim arrays

Use Shape method to find the dimensions of the array.

shape method

Arrange method returns evenly spaced values within a given interval:

arrange method

Reshape method returns an array with the same data with a new shape:

reshape method

Read Also: 5 Integrations for Powerful Automation Testing!

Linspace method returns evenly spaced numbers over a specified interval:

linspace method

Resize method changes the shape and size of the array in-place:

resize method

Read Also : Top 5 Bug Fixing Tools For Python Developers!

Eye method returns a 2D array with ones on the diagonal and zeros elsewhere:

eye method



Operations in NumPy:

We can do various operations with NP arrays such as addition, subtraction, multiplication, division and power as shown below:

add and subtract
addition and subtraction
multiplication and division
multiplication and division
power
power operation
dot product
dot product

 

This would be enough to give you an idea of what are NP arrays and how to deal with them and use operations.

 

Author

Comments are closed.