Short Notes on Numpy

Mallikarjun Yelameli PhD
1 min readSep 18, 2022

The purpose of this post is to refreash essential concepts of Numpy required in the field of data science. So let’s get started.

What is Numpy?

It is the fundamental tool for scientific computing in python, at the core this package is ndarray i.e. n-dimensional array of homogenous data types. The core of Numpy is implemented in C and it provides efficient functions for manipulating and processing arrays.

List vs. Numpy

  1. Numpy array has fixed size of creation, unlike list, which grows dynamically.
  2. The Numpy array has homogeneous data types and thus same size in memory
  3. Numpy arrays facillitate adavanced mathematical and other types of operations.

Why Numpy in fast?

Vectorization is the main reason for numpy to be faster. Vectorization is a array programming style where operations are applied to whole array instead of individual elements. Therefore it excludes any explicit looping, indexing etc.

  1. Vectorized code is more concise and easier to read
  2. Fewer lines of code generally means fewer bugs
  3. Numpy uses fixed type.
  4. List takes large bytes of memory. Numpy takes less bytes of memory.
  5. There no type checking when iterating through objects.

Now let’s look at some of usage example of Numpy

Introduction to Array

Difference between list and array

Import numpy

Create 1D array from list

Create 2D array from lists

Creating an array using Numpy functions

There are many ways to create array using numpy functions, including:

  1. np.zeros()
  2. np.random.random()
  3. np.arange

Array dimensionality

Creating 3D array

Numpy data types

--

--

Mallikarjun Yelameli PhD

An AI/ML enthusiastic | Engineer | Philosophy | Spirituality