NumPy Arrays( Part I )

Vivek Nikam and Abhay Chaudhari
3 min readJul 1, 2021

smart and simple

Photo by Alexandru Acea on Unsplash

Points which we are going to discuss in numpy articles are as follow:

  • What is numpy?
  • Functions in numpy
  • Relational operations on numpy
  • Image operations using numpy

__________________________________________________________________

Numpy stands for numeric python.

Numpy is like a list data structure but more powerful than the list.

First, we have to import the numpy library then we can create a numpy array.

import numpy as np

np is just a short name for numpy so that we can use np instead of numpy.

This is how we can create an array in numpy.

let’s create a 2D array

we can also print the number of rows and columns in an array or dimension of an array.

ndim stands for the number of dimensions.

Indexing and slicing are the same as list but slightly different in 2D array. We will see the slicing of the 2D array in further articles.

Always remember numpy arrays are faster than a list. These are C like arrays.

If an array is 1D then we call it a Vector, Matrix if 2D and Tensor if 3D.

__________________________________________________________________

There are lots of built-in functions to generate Arrays.

  • arange: It is same as range which we have used in for loop.

syntax: np.arange(start,end,step), remember end is exclusive.

  • linspace: stands for linear space. It returns evenly spaced numbers over a specified interval.

syntax: np.linspace(start,end,no. of spaces), here end is inclusive.

for example, if we want 5 spaces between 10 and 20.

By default no. of spaces are 15.

  • zeros: It is used to create an array of zeros.

We can also mention columns and rows for an array.

always provide the number of columns and rows in tuple format.

  • ones: It is used to create an array of ones. it returns values in float datatype.

What if we want to create an array of 10’s, 20's, etc.

We can use zeros as well as ones.

10 gets added to each zero and multiplied with each 1.

This is known as Multicasting.

Thanks for reading!!

--

--