DEV Community

Cover image for Numpy Basics-My experience
MdMusfikurRahmanSifar
MdMusfikurRahmanSifar

Posted on

Numpy Basics-My experience

Numpy is a python library.
One of the most famous ones. Numpy stands for numerical python.
It is used for working with arrays.
Array is like python list but it is more than just list. It is faster than list and also consumes less storage. It's like in math what we call 'matrix'. All that we do with matrices in math we can do with array in numpy in programming rather, using the same theme, numpy has huge amount of other features. It allows us to use data and visualise in a matrix themed way and it is really powerful.

I mentioned previously in

Md. Musfikur Rahman Sifar on LinkedIn: #ml_with_mitul #dive_with_sifar

Week-1 Experience from Basics of Python From my journey of learning python so far, I would describe my experience and understandings in three parts-Notes from…

favicon linkedin.com
what are the basic terms and subtopics of basic python. We always need to keep in mind about those after all we are using python. Here we also have those common topics like slicing, operating etc. So we can easily relate them. So, following that here is the list of the basic topics-
  • Creating arrays

  • Array attributes and methods

  • Slicing

  • Operating

Creating Arrays

we can create arrays two ways-

  • Conversion from other python structures

  • Intrinsic numpy creation objects

Conversion from other python structures(From lists, tuple, etc)

Firstly, we need to import numpy. We can use numpy as np.
import numpy as np
We use array()to create array. The syntax is

import numpy as np
arr=np.array()
Enter fullscreen mode Exit fullscreen mode

array() takes arguements where we can give input.

arrays creating
print
We can create multi-dimensional arrays by putting'[]'
and check the dimension by putting .ndim

Trick: Dimension=Number of '[' from one side

array dim

print
We can take multiple arguments

mul arg
There's also different datatypes..I don't know much about them yet😅

Intrinsic numpy creation objects(arange,zeros,ones etc.)

.arange(start_inclusive,end_exclusive,step)-creates array within the range of number serially
.zeros((row number,column number))-returns array only with 0
.ones((row number,column number))-returns array only with 1
.identity((row-column number))-return identity matrix
methods
print
We can also create random numbers:
.random.rand((row_number,column_number))-creates random number in [0,1) range
.random.randn((row_number,column_number))-Return a sample (or samples) from the "standard normal" distribution. Unlike rand which is uniform
.random.randint((start_inclusive,end_inclusive,total numbers))-random numbers within a range

Array attributes and methods

.max()-returns the maximum entry
.min()-returns the minimum entry
.argmax()-returns the index of max value
.argmin()-returns the index of min value
arrtributes
We can also see the shape of the array and also reshape it
Note:For reshape it must be total entries=new_row*new_column
.shape-to know the shape of the matrix
.reshape-to reshape
attr

Slicing

Syntax:
arrayname[rowstart_inclusive:rowend_exclusive,columnstart_inclusive:columnend_exclusive]
Note:careful about inclusive and exclusive
Slicing

Operating

It is like regular operation in math
Operation

There are also other methods and attributes like-
extra
More we explore more we know about these things and play with them

Experience:

Numpy gets really easy to understand when you relate it with matrix. Know your methods and attributes. But need to be careful about syntax. It was the biggest challenge for me.

There are many other features. It will get even amazing..Still at the beginning...let's continue learning...let's dive together.

Top comments (0)