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
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()
array() takes arguements where we can give input.
We can create multi-dimensional arrays by putting'[]'
and check the dimension by putting .ndim
Trick: Dimension=Number of '[' from one side
We can take multiple arguments
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
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
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
Slicing
Syntax:
arrayname[rowstart_inclusive:rowend_exclusive,columnstart_inclusive:columnend_exclusive]
Note:careful about inclusive and exclusive
Operating
It is like regular operation in math
There are also other methods and attributes like-
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)