Introduction To NumPy Array: A Review Of It's Fundamental Features (Part- I)

Introduction To NumPy Array: A Review Of It's Fundamental Features (Part- I)

Introduction

Did you know? NumPy has been around for over 20 years. It is the fundamental package for scientific computing in python. It is designed to efficiently handle very large, multi-dimensional arrays and perform large matrix operations. If you are one of the hundreds of thousands of people using python for data analysis and modelling, you should use NumPy. Its simple syntax makes it easy to learn. Its sophisticated design makes it powerful, fast and versatile.

NumPy is today's most powerful tool for numerical and scientific computing in python. If you are an experienced programmer, and wish to get started on serious statistical analysis in python, you should learn Numpy first. Numpy is the foundation on which SciPy, pandas and Scikit-learn are built. In this article, I will introduce Numpy to you. We will demonstrate how easy it is to use NumPy by showing you simple examples. we will then move on to more complex examples formula until we reach a place where your experiments lead to conclusions that nobody else could have reached without using some kind of special machinery.

What is NumPy?

NumPy stands for Numerical Python. NumPy is a Python library used for working with arrays. It also has functions for working in domain of linear algebra, fourier transform (Imagine playing a chord on a piano. When played, the sounds of the notes of the chord mix together and form a sound wave. This works because each of the different note's waves interfere with each other by adding together or canceling out at different points in the wave. A Fourier transform takes this complex wave and is able to find the frequencies that made it, meaning it can find the notes that a chord is made from.), matrices. NumPy was created in 2005 by Travis Oliphant. It is an open source project and you can use it freely.

Numpy is also incredibly fast, as it has bindings to C libraries. For more info on why you would want to use Arrays instead of lists, check out this great StackOverflow post here We will only learn the basics of NumPy, to get started we need to install it!

Challenges with NumPy

Despite of numerous strengths NumPy has few disadvantages.

  • Using “nan” in Numpy: “Nan” stands for “not a number”. It was designed to address the problem of missing values. NumPy itself supports “nan” but lack of cross-platform support within Python makes it difficult for the user. That’s why we may face problems when comparing values within the Python interpreter.

  • Require a contiguous allocation of memory: Insertion and deletion operations become costly as data is stored in contiguous memory locations as shifting it requires shifting.

  • Code maintenance — it can be difficult to maintain code that depends heavily on NumPy because there are so many different ways to do things, depending on how much flexibility you want from your code; also, some parts of NumPy aren't well-documented.

How to install and import Numpy Library into your system?

  • Just follow the instructions in the resouces below:

    Youtube : Link

Python Docs: LInk

There are plenty of resouces to instruct how to do that, google will help you out.

How to NumPy create an array?

There are many ways to create the NumPy:

  1. From Python List:

carbon (2).png

  1. From Built-in Methods:

A) Arange : Return evenly spaced values within a given interval.

carbon (3).png

B) Zeros And Ones: Generate an array consiting the combination of 0 and 1.

carbon (5).png

carbon (6).png

C) Linspace: Return evenly spaced numbers over a specified interval.

carbon (7).png

D) Eye: Use for generating identity matrix (here).

carbon (8).png

  1. Random: Numpy also has lots of ways to create random number arrays:

A) Rand : Create an array of the given shape and populate it with random samples from a uniform distribution over "[0, 1)".

carbon (9).png

B) Randn : Return a sample (or samples) from the "standard normal" distribution. Unlike rand which is uniform.

carbon (10).png

D) Randint : Return random integers from low (inclusive) to high (exclusive). Section: the numpy function "array".

carbon (11).png

Array Attributes and Methods

carbon (12).png

A) Reshape: Returns an array containing the same data with a new shape.

carbon (13).png

B) Max, Min, Argmax, Argmin: These are useful methods for finding max or min values. Or to find their index locations using argmin or argmax.

carbon (14).png

C) Shape: its an attribute that arrays have (not a method):

carbon (15).png

carbon (16).png

D) dtype: it tells the datatype of the object in the array.

carbon (17).png

Takeaway

This is a good go-to guide for beginners to learn about NumPy. I know its quite tough to remember all this information. So, that's why the article is divided into two parts. One more thing, you should have some familiarity to Python basics to understand whats going under the hood.

Stay tuned for the next article where we try to dig into NumPy indexing and operations related to NumPy.

Find difficulty to understand and navigate through Python Documentation?? then check Link.