Data science I - Power up your NumPy array skills( Basics)

January 26, 2020 · 5 mins read
Categories: machinelearning   | datascience   | python   | numpy |

The first and foremost thing you need to get started in the data science and machine learning world is to have a little bit of knowledge of Python/ R.

And I already know a little bit of Python and have worked on it for some time in the past, I will be choosing it over R.

What are we going to learn today?

Before you start on applying various algorithms to data to find the answers present in the data, you should be able to know the tools which you can use to apply the various operations.

The first tool which is going to help us a lot is the Numpy library.

In this tutorial, we are going to talk about the basics of NumPy library which will help us to apply all the mathematical operations to the data sets that we will receive later during the learning.

You can go forward and install the virtual environment along with jupyter notebook. While in the virtual environment, all you have to do is,

pip install jupyter
These things are pretty straight forward, so I would leave you to figure these things out on your own.

After installing jupyter notebook you can start off the jupyter notebook and rest of the installations we can directly do from the jupyter notebook itself.

You can start the jupyter notebook using the command.

jupyter notebook
Create a new python3 notebook from the new button on the right hand side.

Introduction to Numpy

NumPy is a Linear Algebra Library for Python. This particular library can be used to make all sorts of maths related computations in python.

Also, they are blazingly fast because it is executed with pre compiled C code.

It is also important because almost all the libraries of PyData ecosystem are somehow dependent on NumPy library.

You can install NumPy using pip.

While in the newly created jupyter notebook, go to the first shell and use the following command.

!pip install numpy
You can run a jupyter notebook block using the combination of shift + return( Enter).

Installing numpy using jupyter notebook

We will mostly be using the NumPy arrays to interact with the data.

There are a few terminologies we need to be aware of before moving forward.

  • Vectors: These are the 1-d arrays.
  • Matrices: These are the 2-d arrays but can have 1 row or 1 column as well.
So essentially, a matrix with 1 row or 1 column can be known as a vector as well.

In general, people import Numpy as np to save time, you can use the same standard or prefer to stay away from it as well.

import numpy as np
Note: The combination of vectors and matrices are referred as NumPy arrays. From now on we use the same analogy.

NumPy vectors and matrices creation and library methods

Let’s move to the jupyter notebook for the further discussions of numpy.

In this jupyter notebook, we are going to create NumPy vectors and matrices using different methods.

We are also going to talk about different basic methods that will play an important role while performing different tasks on data sets.

Numpy learning jupyter notebook

Selecting data using Numpy Array Indexing/ Positioning

All these methods are used to select specific parts and particular element from the NumPy arrays.

Let’s move to the jupyter notebook and continue the tutorial up there.

In this part, we are going to learn about selecting different parts of the np arrays. Along with some basic conditional selecting, where you select certain parts using some specific conditions.

Numpy Selection Jupyter Notebook

Learning about Numpy operations available

Numpy operation can help us do different operation on the elements of the np arrays and give us the desired results.

In this jupyter notebook, we will be talking about the 3 types of operations.

  • Vector Operations
The operations in which two arrays are involved. The result of such operation will be arrays as well.

  • Scalar Operations
One Scalar and one np array is involved in such operations.

  • Universal Operators
Math operators that we apply to NumPy arrays.

Find more operators related to Numpy here.

NumPy operators jupyter notebooks

That’s it for today’s article, hope you find this useful and share it with your friends.

If you want to get updates about the new posts shared, please consider subscribing to the newsletter.

Please share your Feedback:

Did you enjoy reading or think it can be improved? Don’t forget to leave your thoughts in the comments section below! If you liked this article, please share it with your friends, and read a few more!

We don't share your details with others