Numpy basics for beginners

Photo by Andrew Buchanan on Unsplash

If you have just started or you are looking for a quick reference to useful numpy functions then you are in the right place. For advanced methods, this page might seem very basic, but hey check out, who knows you might find something interesting :)

Now, i have tried to cover some key areas, where we often struggle: looping, doing some indexing, slicing, statistics and (not to forget) linear algebra. Also, consider my methods or approaches as few of the many possibilities offered by numpy.

Let’s dive in:

create 1 a: Lets create our numpy arrays: 1-d, 2-d 3–d

created similarly but 2-d, 3-d, 4-d

create 1 b: There’s another way to create numpy arrays: np.arange and reshape()

using arange then reshape

create 1 c: random.rand, random.random, random.normal, random.uniform, random.randint

slicing : slice a 2-d array and get 1-d, 2-d and single element

arr[x,y] -> x handles the rows and y handles the columns

Loop 1a: using for loop and np.nditer

np.nditer by default don’t allow users to modify elements but we can do it by using op_flags

Statistical functions

a. variance and standard deviation

b. percentile

c. weighted average

d. covariance and correlation

Linear algebra

the ones that are frequently used are dot, matmul, inner product, tensor product and an understanding of how a linear equation can be transformed into a matrix form will be useful.

a. dot and matmul

b. inner and tensor

c. Linear equation to matrix form

That’s all for this time. Hope you all like it :)

Happy learning !




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dipanwita Mallick

Dipanwita Mallick

I am working as a Senior Data Scientist at Hewlett Packard Enterprise. I love exploring new ideas and new places !! :)